mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 03:57:43 +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
|
@ -1,5 +1,4 @@
|
|||
#include <AK/TemporaryChange.h>
|
||||
#include <Kernel/Alarm.h>
|
||||
#include <Kernel/Arch/i386/PIT.h>
|
||||
#include <Kernel/Devices/PCSpeaker.h>
|
||||
#include <Kernel/FileSystem/FileDescription.h>
|
||||
|
@ -159,9 +158,9 @@ bool Scheduler::pick_next()
|
|||
return IterationDecision::Continue;
|
||||
}
|
||||
|
||||
if (thread.state() == Thread::BlockedSnoozing) {
|
||||
if (thread.m_snoozing_alarm->is_ringing()) {
|
||||
thread.m_snoozing_alarm = nullptr;
|
||||
if (thread.state() == Thread::BlockedCondition) {
|
||||
if (thread.m_block_until_condition()) {
|
||||
thread.m_block_until_condition = nullptr;
|
||||
thread.unblock();
|
||||
}
|
||||
return IterationDecision::Continue;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue