mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 20:45:14 +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
Notes:
sideshowbarker
2024-07-19 13:09:38 +09:00
Author: https://github.com/rburchell Commit: https://github.com/SerenityOS/serenity/commit/d2ca91c024e Pull-request: https://github.com/SerenityOS/serenity/pull/340
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()) {
|
||||
current->block(Thread::State::BlockedSignal);
|
||||
current->block(*new Thread::SemiPermanentBlocker(Thread::SemiPermanentBlocker::Reason::Signal));
|
||||
if (nwritten == 0)
|
||||
return -EINTR;
|
||||
}
|
||||
|
@ -914,7 +914,7 @@ ssize_t Process::do_write(FileDescription& description, const u8* data, int data
|
|||
if (rc == 0)
|
||||
break;
|
||||
if (current->has_unmasked_pending_signals()) {
|
||||
current->block(Thread::State::BlockedSignal);
|
||||
current->block(*new Thread::SemiPermanentBlocker(Thread::SemiPermanentBlocker::Reason::Signal));
|
||||
if (nwritten == 0)
|
||||
return -EINTR;
|
||||
}
|
||||
|
@ -939,7 +939,7 @@ ssize_t Process::sys$write(int fd, const u8* data, ssize_t size)
|
|||
return -EBADF;
|
||||
auto nwritten = do_write(*description, data, size);
|
||||
if (current->has_unmasked_pending_signals()) {
|
||||
current->block(Thread::State::BlockedSignal);
|
||||
current->block(*new Thread::SemiPermanentBlocker(Thread::SemiPermanentBlocker::Reason::Signal));
|
||||
if (nwritten == 0)
|
||||
return -EINTR;
|
||||
}
|
||||
|
@ -1265,7 +1265,7 @@ int Process::sys$kill(pid_t pid, int signal)
|
|||
}
|
||||
if (pid == m_pid) {
|
||||
current->send_signal(signal, this);
|
||||
current->block(Thread::State::BlockedSignal);
|
||||
current->block(*new Thread::SemiPermanentBlocker(Thread::SemiPermanentBlocker::Reason::Signal));
|
||||
return 0;
|
||||
}
|
||||
InterruptDisabler disabler;
|
||||
|
|
|
@ -201,6 +201,16 @@ bool Thread::WaitBlocker::should_unblock(Thread& thread, time_t, long)
|
|||
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.
|
||||
// Make a decision as to whether to unblock them or not.
|
||||
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::Dead:
|
||||
case Thread::Stopped:
|
||||
case Thread::BlockedLurking:
|
||||
case Thread::BlockedSignal:
|
||||
/* don't know, don't care */
|
||||
return;
|
||||
case Thread::BlockedCondition:
|
||||
|
@ -234,7 +242,7 @@ void Thread::consider_unblock(time_t now_sec, long now_usec)
|
|||
return;
|
||||
case Thread::Dying:
|
||||
ASSERT(g_finalizer);
|
||||
if (g_finalizer->state() == Thread::BlockedLurking)
|
||||
if (g_finalizer->is_blocked())
|
||||
g_finalizer->unblock();
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -162,10 +162,6 @@ const char* to_string(Thread::State state)
|
|||
return "Skip1";
|
||||
case Thread::Skip0SchedulerPasses:
|
||||
return "Skip0";
|
||||
case Thread::BlockedSignal:
|
||||
return "Signal";
|
||||
case Thread::BlockedLurking:
|
||||
return "Lurking";
|
||||
case Thread::BlockedCondition:
|
||||
return "Condition";
|
||||
case Thread::__Begin_Blocked_States__:
|
||||
|
@ -349,9 +345,7 @@ ShouldUnblockThread Thread::dispatch_signal(u8 signal)
|
|||
m_process.terminate_due_to_signal(signal);
|
||||
return ShouldUnblockThread::No;
|
||||
case DefaultSignalAction::Ignore:
|
||||
if (state() == BlockedSignal)
|
||||
set_state(Runnable);
|
||||
return ShouldUnblockThread::No;
|
||||
ASSERT_NOT_REACHED();
|
||||
case DefaultSignalAction::Continue:
|
||||
return ShouldUnblockThread::Yes;
|
||||
}
|
||||
|
|
|
@ -65,8 +65,6 @@ public:
|
|||
Stopped,
|
||||
|
||||
__Begin_Blocked_States__,
|
||||
BlockedLurking,
|
||||
BlockedSignal,
|
||||
BlockedCondition,
|
||||
__End_Blocked_States__
|
||||
};
|
||||
|
@ -158,6 +156,20 @@ public:
|
|||
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; }
|
||||
u32 times_scheduled() const { return m_times_scheduled; }
|
||||
|
||||
|
|
|
@ -242,7 +242,7 @@ extern "C" [[noreturn]] void init()
|
|||
current->process().set_priority(Process::LowPriority);
|
||||
for (;;) {
|
||||
Thread::finalize_dying_threads();
|
||||
current->block(Thread::BlockedLurking);
|
||||
current->block(*new Thread::SemiPermanentBlocker(Thread::SemiPermanentBlocker::Reason::Lurking));
|
||||
Scheduler::yield();
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue