mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-07 00:56:14 +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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user