From bc1da7f1fd2e366d290db4b33f07b9806d2a6932 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 20 Mar 2019 17:09:46 +0100 Subject: Kernel: Snooze the NetworkTask until there are incoming packets to process. This is accomplished using a new Alarm class and a BlockedSnoozing state. Basically, you call Process::snooze_until(some_alarm) and then the scheduler won't wake up the process until some_alarm.is_ringing() returns true. --- Kernel/NetworkAdapter.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'Kernel/NetworkAdapter.h') diff --git a/Kernel/NetworkAdapter.h b/Kernel/NetworkAdapter.h index 512c80dfa4..a040aaced2 100644 --- a/Kernel/NetworkAdapter.h +++ b/Kernel/NetworkAdapter.h @@ -7,6 +7,18 @@ #include #include #include +#include + +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: @@ -24,6 +36,10 @@ 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: NetworkAdapter(); void set_mac_address(const MACAddress& mac_address) { m_mac_address = mac_address; } @@ -33,5 +49,6 @@ protected: private: MACAddress m_mac_address; IPv4Address m_ipv4_address; + PacketQueueAlarm m_packet_queue_alarm; SinglyLinkedList m_packet_queue; }; -- cgit v1.2.3