diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-07-14 14:51:54 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-07-14 14:54:54 +0200 |
commit | b2e502e533173594431b53ef551bd64bbb85ae4f (patch) | |
tree | febf7bc78f419c6088bc903e36f71f78bfd803ec /Kernel/Net | |
parent | e8d61bb8c0580683fcbc171825c680ef106024d6 (diff) | |
download | serenity-b2e502e533173594431b53ef551bd64bbb85ae4f.zip |
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 :^)
Diffstat (limited to 'Kernel/Net')
-rw-r--r-- | Kernel/Net/NetworkAdapter.cpp | 6 | ||||
-rw-r--r-- | Kernel/Net/NetworkAdapter.h | 17 | ||||
-rw-r--r-- | Kernel/Net/NetworkTask.cpp | 28 |
3 files changed, 9 insertions, 42 deletions
diff --git a/Kernel/Net/NetworkAdapter.cpp b/Kernel/Net/NetworkAdapter.cpp index f1eaffc245..f4ef012c4f 100644 --- a/Kernel/Net/NetworkAdapter.cpp +++ b/Kernel/Net/NetworkAdapter.cpp @@ -33,7 +33,6 @@ NetworkAdapter* NetworkAdapter::from_ipv4_address(const IPv4Address& address) } NetworkAdapter::NetworkAdapter() - : m_packet_queue_alarm(*this) { // FIXME: I wanna lock :( all_adapters().resource().set(this); @@ -106,8 +105,3 @@ void NetworkAdapter::set_interface_name(const StringView& basename) builder.append('0'); m_name = builder.to_string(); } - -bool PacketQueueAlarm::is_ringing() const -{ - return m_adapter.has_queued_packets(); -} diff --git a/Kernel/Net/NetworkAdapter.h b/Kernel/Net/NetworkAdapter.h index 118bb13774..2052b3cc43 100644 --- a/Kernel/Net/NetworkAdapter.h +++ b/Kernel/Net/NetworkAdapter.h @@ -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; }; diff --git a/Kernel/Net/NetworkTask.cpp b/Kernel/Net/NetworkTask.cpp index c680a66135..5c553e7cd2 100644 --- a/Kernel/Net/NetworkTask.cpp +++ b/Kernel/Net/NetworkTask.cpp @@ -33,22 +33,6 @@ Lockable<HashMap<IPv4Address, MACAddress>>& arp_table() return *the; } -class CombinedPacketQueueAlarm : public Alarm { -public: - CombinedPacketQueueAlarm() {} - - virtual bool is_ringing() const override - { - if (LoopbackAdapter::the().has_queued_packets()) - return true; - if (auto* e1000 = E1000NetworkAdapter::the()) { - if (e1000->has_queued_packets()) - return true; - } - return false; - } -}; - void NetworkTask_main() { LoopbackAdapter::the(); @@ -71,13 +55,19 @@ void NetworkTask_main() return {}; }; - CombinedPacketQueueAlarm queue_alarm; - kprintf("NetworkTask: Enter main loop.\n"); for (;;) { auto packet = dequeue_packet(); if (packet.is_null()) { - current->snooze_until(queue_alarm); + current->block_until([] { + if (LoopbackAdapter::the().has_queued_packets()) + return true; + if (auto* e1000 = E1000NetworkAdapter::the()) { + if (e1000->has_queued_packets()) + return true; + } + return false; + }); continue; } if (packet.size() < (int)(sizeof(EthernetFrameHeader))) { |