1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 01:37:35 +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

@ -4,7 +4,6 @@
#include <AK/Function.h>
#include <AK/SinglyLinkedList.h>
#include <AK/Types.h>
#include <Kernel/Alarm.h>
#include <Kernel/Net/ARP.h>
#include <Kernel/Net/ICMP.h>
#include <Kernel/Net/IPv4.h>
@ -12,19 +11,6 @@
class NetworkAdapter;
class PacketQueueAlarm final : public Alarm {
public:
PacketQueueAlarm(NetworkAdapter& adapter)
: m_adapter(adapter)
{
}
virtual ~PacketQueueAlarm() override {}
virtual bool is_ringing() const override;
private:
NetworkAdapter& m_adapter;
};
class NetworkAdapter {
public:
static void for_each(Function<void(NetworkAdapter&)>);
@ -44,8 +30,6 @@ public:
ByteBuffer dequeue_packet();
Alarm& packet_queue_alarm() { return m_packet_queue_alarm; }
bool has_queued_packets() const { return !m_packet_queue.is_empty(); }
protected:
@ -58,7 +42,6 @@ protected:
private:
MACAddress m_mac_address;
IPv4Address m_ipv4_address;
PacketQueueAlarm m_packet_queue_alarm;
SinglyLinkedList<ByteBuffer> m_packet_queue;
String m_name;
};