1
0
mirror of https://github.com/deavmi/birchwood synced 2024-09-20 13:43:19 +02:00
- Updated `sendHandlerFunc()` to use the condition variable
- Callind `end()` will wakeup the sleeping thread
This commit is contained in:
Tristan B. Velloza Kildaire 2023-10-23 22:19:07 +02:00
parent 3c97e9db9d
commit fca776c29b

View File

@ -89,36 +89,14 @@ public final class SenderThread : Thread
{ {
while(client.isRunning()) while(client.isRunning())
{ {
// TODO: We could look at libsnooze wait starvation or mutex racing (future thought)
/* TODO: handle normal messages (xCount with fakeLagInBetween) */ /* TODO: handle normal messages (xCount with fakeLagInBetween) */
try /* Lock the queue */
{
sendEvent.wait();
}
catch(InterruptedException e)
{
version(unittest)
{
writeln("wait() interrupted");
}
continue;
}
catch(FatalException e)
{
// TODO: This should crash and end
version(unittest)
{
writeln("wait() had a FATAL error!!!!!!!!!!!");
}
continue;
}
/* Lock queue */
sendQueueLock.lock(); sendQueueLock.lock();
/* Sleep till woken (new message) */
sendQueueCond.wait(); // TODO: Check SyncError?
foreach(ubyte[] message; sendQueue[]) foreach(ubyte[] message; sendQueue[])
{ {
client.socket.send(message); client.socket.send(message);
@ -138,14 +116,16 @@ public final class SenderThread : Thread
*/ */
public void end() public void end()
{ {
// TODO: See above notes about libsnooze behaviour due /* Lock the queue */
// ... to usage in our context sendQueueLock.lock();
sendEvent.notifyAll();
/* Wake up sleeping thread (so it can exit) */
sendQueueCond.notify();
/* Unlock the queue */
sendQueueLock.unlock();
// Wait on the manager thread to end // Wait on the manager thread to end
join(); join();
// Dispose the eventy event (TODO: We could do this then join for same effect)
sendEvent.dispose();
} }
} }