mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:28:12 +00:00
Kernel: Add Thread::block_until(Condition).
Replace the class-based snooze alarm mechanism with a per-thread callback. This makes it easy to block the current thread on an arbitrary condition: void SomeDevice::wait_for_irq() { m_interrupted = false; current->block_until([this] { return m_interrupted; }); } void SomeDevice::handle_irq() { m_interrupted = true; } Use this in the SB16 driver, and in NetworkTask :^)
This commit is contained in:
parent
e8d61bb8c0
commit
b2e502e533
8 changed files with 22 additions and 78 deletions
|
@ -108,10 +108,10 @@ void Thread::unblock()
|
|||
set_state(Thread::Runnable);
|
||||
}
|
||||
|
||||
void Thread::snooze_until(Alarm& alarm)
|
||||
void Thread::block_until(Function<bool()>&& condition)
|
||||
{
|
||||
m_snoozing_alarm = &alarm;
|
||||
block(Thread::BlockedSnoozing);
|
||||
m_block_until_condition = move(condition);
|
||||
block(Thread::BlockedCondition);
|
||||
Scheduler::yield();
|
||||
}
|
||||
|
||||
|
@ -179,8 +179,8 @@ const char* to_string(Thread::State state)
|
|||
return "Connect";
|
||||
case Thread::BlockedReceive:
|
||||
return "Receive";
|
||||
case Thread::BlockedSnoozing:
|
||||
return "Snoozing";
|
||||
case Thread::BlockedCondition:
|
||||
return "Condition";
|
||||
case Thread::__Begin_Blocked_States__:
|
||||
case Thread::__End_Blocked_States__:
|
||||
break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue