Skip to content

Commit

Permalink
Sender
Browse files Browse the repository at this point in the history
- Updated `sendHandlerFunc()` to use the condition variable
- Callind `end()` will wakeup the sleeping thread
  • Loading branch information
deavmi committed Oct 23, 2023
1 parent 3c97e9d commit fca776c
Showing 1 changed file with 12 additions and 32 deletions.
44 changes: 12 additions & 32 deletions source/birchwood/client/sender.d
Original file line number Diff line number Diff line change
Expand Up @@ -89,36 +89,14 @@ public final class SenderThread : Thread
{
while(client.isRunning())
{
// TODO: We could look at libsnooze wait starvation or mutex racing (future thought)

/* TODO: handle normal messages (xCount with fakeLagInBetween) */

try
{
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 */
/* Lock the queue */
sendQueueLock.lock();

/* Sleep till woken (new message) */
sendQueueCond.wait(); // TODO: Check SyncError?

foreach(ubyte[] message; sendQueue[])
{
client.socket.send(message);
Expand All @@ -138,14 +116,16 @@ public final class SenderThread : Thread
*/
public void end()
{
// TODO: See above notes about libsnooze behaviour due
// ... to usage in our context
sendEvent.notifyAll();
/* Lock the queue */
sendQueueLock.lock();

/* Wake up sleeping thread (so it can exit) */
sendQueueCond.notify();

/* Unlock the queue */
sendQueueLock.unlock();

// Wait on the manager thread to end
join();

// Dispose the eventy event (TODO: We could do this then join for same effect)
sendEvent.dispose();
}
}

0 comments on commit fca776c

Please sign in to comment.