mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 00:07:34 +00:00
Kernel: Convert BlockedSignal and BlockedLurking to the new Blocker mechanism
The last two of the old block states gone :)
This commit is contained in:
parent
750dbe986d
commit
d2ca91c024
5 changed files with 31 additions and 17 deletions
|
@ -869,7 +869,7 @@ ssize_t Process::sys$writev(int fd, const struct iovec* iov, int iov_count)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current->has_unmasked_pending_signals()) {
|
if (current->has_unmasked_pending_signals()) {
|
||||||
current->block(Thread::State::BlockedSignal);
|
current->block(*new Thread::SemiPermanentBlocker(Thread::SemiPermanentBlocker::Reason::Signal));
|
||||||
if (nwritten == 0)
|
if (nwritten == 0)
|
||||||
return -EINTR;
|
return -EINTR;
|
||||||
}
|
}
|
||||||
|
@ -914,7 +914,7 @@ ssize_t Process::do_write(FileDescription& description, const u8* data, int data
|
||||||
if (rc == 0)
|
if (rc == 0)
|
||||||
break;
|
break;
|
||||||
if (current->has_unmasked_pending_signals()) {
|
if (current->has_unmasked_pending_signals()) {
|
||||||
current->block(Thread::State::BlockedSignal);
|
current->block(*new Thread::SemiPermanentBlocker(Thread::SemiPermanentBlocker::Reason::Signal));
|
||||||
if (nwritten == 0)
|
if (nwritten == 0)
|
||||||
return -EINTR;
|
return -EINTR;
|
||||||
}
|
}
|
||||||
|
@ -939,7 +939,7 @@ ssize_t Process::sys$write(int fd, const u8* data, ssize_t size)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
auto nwritten = do_write(*description, data, size);
|
auto nwritten = do_write(*description, data, size);
|
||||||
if (current->has_unmasked_pending_signals()) {
|
if (current->has_unmasked_pending_signals()) {
|
||||||
current->block(Thread::State::BlockedSignal);
|
current->block(*new Thread::SemiPermanentBlocker(Thread::SemiPermanentBlocker::Reason::Signal));
|
||||||
if (nwritten == 0)
|
if (nwritten == 0)
|
||||||
return -EINTR;
|
return -EINTR;
|
||||||
}
|
}
|
||||||
|
@ -1265,7 +1265,7 @@ int Process::sys$kill(pid_t pid, int signal)
|
||||||
}
|
}
|
||||||
if (pid == m_pid) {
|
if (pid == m_pid) {
|
||||||
current->send_signal(signal, this);
|
current->send_signal(signal, this);
|
||||||
current->block(Thread::State::BlockedSignal);
|
current->block(*new Thread::SemiPermanentBlocker(Thread::SemiPermanentBlocker::Reason::Signal));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
InterruptDisabler disabler;
|
InterruptDisabler disabler;
|
||||||
|
|
|
@ -201,6 +201,16 @@ bool Thread::WaitBlocker::should_unblock(Thread& thread, time_t, long)
|
||||||
return should_unblock;
|
return should_unblock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Thread::SemiPermanentBlocker::SemiPermanentBlocker(Reason reason)
|
||||||
|
: m_reason(reason)
|
||||||
|
{}
|
||||||
|
|
||||||
|
bool Thread::SemiPermanentBlocker::should_unblock(Thread&, time_t, long)
|
||||||
|
{
|
||||||
|
// someone else has to unblock us
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Called by the scheduler on threads that are blocked for some reason.
|
// Called by the scheduler on threads that are blocked for some reason.
|
||||||
// Make a decision as to whether to unblock them or not.
|
// Make a decision as to whether to unblock them or not.
|
||||||
void Thread::consider_unblock(time_t now_sec, long now_usec)
|
void Thread::consider_unblock(time_t now_sec, long now_usec)
|
||||||
|
@ -215,8 +225,6 @@ void Thread::consider_unblock(time_t now_sec, long now_usec)
|
||||||
case Thread::Running:
|
case Thread::Running:
|
||||||
case Thread::Dead:
|
case Thread::Dead:
|
||||||
case Thread::Stopped:
|
case Thread::Stopped:
|
||||||
case Thread::BlockedLurking:
|
|
||||||
case Thread::BlockedSignal:
|
|
||||||
/* don't know, don't care */
|
/* don't know, don't care */
|
||||||
return;
|
return;
|
||||||
case Thread::BlockedCondition:
|
case Thread::BlockedCondition:
|
||||||
|
@ -234,7 +242,7 @@ void Thread::consider_unblock(time_t now_sec, long now_usec)
|
||||||
return;
|
return;
|
||||||
case Thread::Dying:
|
case Thread::Dying:
|
||||||
ASSERT(g_finalizer);
|
ASSERT(g_finalizer);
|
||||||
if (g_finalizer->state() == Thread::BlockedLurking)
|
if (g_finalizer->is_blocked())
|
||||||
g_finalizer->unblock();
|
g_finalizer->unblock();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,10 +162,6 @@ const char* to_string(Thread::State state)
|
||||||
return "Skip1";
|
return "Skip1";
|
||||||
case Thread::Skip0SchedulerPasses:
|
case Thread::Skip0SchedulerPasses:
|
||||||
return "Skip0";
|
return "Skip0";
|
||||||
case Thread::BlockedSignal:
|
|
||||||
return "Signal";
|
|
||||||
case Thread::BlockedLurking:
|
|
||||||
return "Lurking";
|
|
||||||
case Thread::BlockedCondition:
|
case Thread::BlockedCondition:
|
||||||
return "Condition";
|
return "Condition";
|
||||||
case Thread::__Begin_Blocked_States__:
|
case Thread::__Begin_Blocked_States__:
|
||||||
|
@ -349,9 +345,7 @@ ShouldUnblockThread Thread::dispatch_signal(u8 signal)
|
||||||
m_process.terminate_due_to_signal(signal);
|
m_process.terminate_due_to_signal(signal);
|
||||||
return ShouldUnblockThread::No;
|
return ShouldUnblockThread::No;
|
||||||
case DefaultSignalAction::Ignore:
|
case DefaultSignalAction::Ignore:
|
||||||
if (state() == BlockedSignal)
|
ASSERT_NOT_REACHED();
|
||||||
set_state(Runnable);
|
|
||||||
return ShouldUnblockThread::No;
|
|
||||||
case DefaultSignalAction::Continue:
|
case DefaultSignalAction::Continue:
|
||||||
return ShouldUnblockThread::Yes;
|
return ShouldUnblockThread::Yes;
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,8 +65,6 @@ public:
|
||||||
Stopped,
|
Stopped,
|
||||||
|
|
||||||
__Begin_Blocked_States__,
|
__Begin_Blocked_States__,
|
||||||
BlockedLurking,
|
|
||||||
BlockedSignal,
|
|
||||||
BlockedCondition,
|
BlockedCondition,
|
||||||
__End_Blocked_States__
|
__End_Blocked_States__
|
||||||
};
|
};
|
||||||
|
@ -158,6 +156,20 @@ public:
|
||||||
pid_t& m_waitee_pid;
|
pid_t& m_waitee_pid;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class SemiPermanentBlocker : public Blocker {
|
||||||
|
public:
|
||||||
|
enum class Reason {
|
||||||
|
Lurking,
|
||||||
|
Signal,
|
||||||
|
};
|
||||||
|
|
||||||
|
SemiPermanentBlocker(Reason reason);
|
||||||
|
virtual bool should_unblock(Thread&, time_t, long) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Reason m_reason;
|
||||||
|
};
|
||||||
|
|
||||||
void did_schedule() { ++m_times_scheduled; }
|
void did_schedule() { ++m_times_scheduled; }
|
||||||
u32 times_scheduled() const { return m_times_scheduled; }
|
u32 times_scheduled() const { return m_times_scheduled; }
|
||||||
|
|
||||||
|
|
|
@ -242,7 +242,7 @@ extern "C" [[noreturn]] void init()
|
||||||
current->process().set_priority(Process::LowPriority);
|
current->process().set_priority(Process::LowPriority);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
Thread::finalize_dying_threads();
|
Thread::finalize_dying_threads();
|
||||||
current->block(Thread::BlockedLurking);
|
current->block(*new Thread::SemiPermanentBlocker(Thread::SemiPermanentBlocker::Reason::Lurking));
|
||||||
Scheduler::yield();
|
Scheduler::yield();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue