1
0
mirror of https://github.com/deavmi/birchwood synced 2024-09-20 13:43:19 +02:00
- Calling `sq(ubyte[])` now will wake up the condition variable
This commit is contained in:
Tristan B. Velloza Kildaire 2023-10-23 22:14:05 +02:00
parent c25c28c256
commit 3c97e9db9d

View File

@ -7,6 +7,7 @@ import core.thread : Thread, dur;
import std.container.slist : SList; import std.container.slist : SList;
import core.sync.mutex : Mutex; import core.sync.mutex : Mutex;
import core.sync.condition : Condition;
import birchwood.client; import birchwood.client;
@ -31,11 +32,10 @@ public final class SenderThread : Thread
private Mutex sendQueueLock; private Mutex sendQueueLock;
/** /**
* The libsnooze event to await on which * Condition variable for waking
* when we wake up signals a new message * up send queue reader
* to be processed and sent
*/ */
private Event sendEvent; private Condition sendQueueCond;
/** /**
* The associated IRC client * The associated IRC client
@ -56,9 +56,8 @@ public final class SenderThread : Thread
{ {
super(&sendHandlerFunc); super(&sendHandlerFunc);
this.client = client; this.client = client;
this.sendEvent = new Event();
this.sendQueueLock = new Mutex(); 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 */ /* Add to queue */
sendQueue.insertAfter(sendQueue[], encodedMessage); sendQueue.insertAfter(sendQueue[], encodedMessage);
/* Wake the sleeping message handler */
sendQueueCond.notify();
/* Unlock queue */ /* Unlock queue */
sendQueueLock.unlock(); sendQueueLock.unlock();
/**
* Wake up all threads waiting on this event
* (if any, and if so it would only be the sender)
*/
sendEvent.notifyAll();
} }
/** /**