mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:08: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:
parent
e8d61bb8c0
commit
b2e502e533
8 changed files with 22 additions and 78 deletions
|
@ -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