1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 07:38:10 +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:
Andreas Kling 2019-07-14 14:51:54 +02:00
parent e8d61bb8c0
commit b2e502e533
8 changed files with 22 additions and 78 deletions

View file

@ -1,6 +1,7 @@
#pragma once
#include <AK/AKString.h>
#include <AK/Function.h>
#include <AK/InlineLinkedList.h>
#include <AK/OwnPtr.h>
#include <AK/RefPtr.h>
@ -72,7 +73,7 @@ public:
BlockedSelect,
BlockedConnect,
BlockedReceive,
BlockedSnoozing,
BlockedCondition,
__End_Blocked_States__
};
@ -102,7 +103,7 @@ public:
void set_wakeup_time(u64 t) { m_wakeup_time = t; }
u64 wakeup_time() const { return m_wakeup_time; }
void snooze_until(Alarm&);
void block_until(Function<bool()>&&);
KResult wait_for_connect(FileDescription&);
const FarPtr& far_ptr() const { return m_far_ptr; }
@ -187,7 +188,7 @@ private:
timeval m_select_timeout;
SignalActionData m_signal_action_data[32];
Region* m_signal_stack_user_region { nullptr };
Alarm* m_snoozing_alarm { nullptr };
Function<bool()> m_block_until_condition;
Vector<int> m_select_read_fds;
Vector<int> m_select_write_fds;
Vector<int> m_select_exceptional_fds;