From 3c97e9db9d4c3db61f2353447061664a1fe0cebf Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Mon, 23 Oct 2023 22:14:05 +0200 Subject: [PATCH] Sender - Calling `sq(ubyte[])` now will wake up the condition variable --- source/birchwood/client/sender.d | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/source/birchwood/client/sender.d b/source/birchwood/client/sender.d index eb6cef7..b2d3c93 100644 --- a/source/birchwood/client/sender.d +++ b/source/birchwood/client/sender.d @@ -7,6 +7,7 @@ import core.thread : Thread, dur; import std.container.slist : SList; import core.sync.mutex : Mutex; +import core.sync.condition : Condition; import birchwood.client; @@ -31,11 +32,10 @@ public final class SenderThread : Thread private Mutex sendQueueLock; /** - * The libsnooze event to await on which - * when we wake up signals a new message - * to be processed and sent + * Condition variable for waking + * up send queue reader */ - private Event sendEvent; + private Condition sendQueueCond; /** * The associated IRC client @@ -56,9 +56,8 @@ public final class SenderThread : Thread { super(&sendHandlerFunc); this.client = client; - this.sendEvent = new Event(); this.sendQueueLock = new Mutex(); - this.sendEvent.ensure(this); + this.sendQueueCond = new Condition(this.sendQueueLock); } /** @@ -76,14 +75,11 @@ public final class SenderThread : Thread /* Add to queue */ sendQueue.insertAfter(sendQueue[], encodedMessage); + /* Wake the sleeping message handler */ + sendQueueCond.notify(); + /* Unlock queue */ sendQueueLock.unlock(); - - /** - * Wake up all threads waiting on this event - * (if any, and if so it would only be the sender) - */ - sendEvent.notifyAll(); } /**