mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 16:57:46 +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
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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))) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue