diff --git a/source/birchwood/client/client.d b/source/birchwood/client/client.d index 34e49cd..26739b1 100644 --- a/source/birchwood/client/client.d +++ b/source/birchwood/client/client.d @@ -661,6 +661,12 @@ public class Client : Thread socket.close(); logger.log("disconnect() socket closed"); + // TODO: See libsnooze notes in `receiver.d` and `sender.d`, we could technically in some + // ... teribble situation have a unregistered situaion which would then have a fallthrough + // ... notify and a wait which never wakes up (the solution is mentioned in `receiver.d`/`sender.d`) + receiver.end(); + sender.end(); + /* Wait for receive queue manager to realise it needs to stop */ receiver.join(); logger.log("disconnect() recvQueue manager stopped"); diff --git a/source/birchwood/client/receiver.d b/source/birchwood/client/receiver.d index b1cb7ca..bfca735 100644 --- a/source/birchwood/client/receiver.d +++ b/source/birchwood/client/receiver.d @@ -63,7 +63,15 @@ public final class ReceiverThread : Thread /* Unlock queue */ recvQueueLock.unlock(); - // TODO: Add libsnooze event wake up + // TODO: Add a "register" function which can initialize pipes + // ... without needing a wait, we'd need a ready flag though + // ... for receiver's thread start + + /** + * Wake up all threads waiting on this event + * (if any, and if so it would only be the receiver) + */ + receiveEvent.notifyAll(); } /** @@ -91,6 +99,10 @@ public final class ReceiverThread : Thread // TODO: We could look at libsnooze wait starvation or mutex racing (future thought) + // TODO: See above notes about libsnooze behaviour due + // ... to usage in our context + receiveEvent.wait(); // TODO: Catch any exceptions from libsnooze + /* Lock the receieve queue */ recvQueueLock.lock(); @@ -185,14 +197,15 @@ public final class ReceiverThread : Thread client.engine.push(ircEvent); } - - - /* Unlock the receive queue */ recvQueueLock.unlock(); - - /* TODO: Threading yield here */ - Thread.yield(); } } + + public void end() + { + // TODO: See above notes about libsnooze behaviour due + // ... to usage in our context + receiveEvent.notifyAll(); + } } \ No newline at end of file diff --git a/source/birchwood/client/sender.d b/source/birchwood/client/sender.d index 8425e0e..3bd9bb9 100644 --- a/source/birchwood/client/sender.d +++ b/source/birchwood/client/sender.d @@ -58,7 +58,15 @@ public final class SenderThread : Thread /* Unlock queue */ sendQueueLock.unlock(); - // TODO: Add libsnooze event wake up + // TODO: Add a "register" function which can initialize pipes + // ... without needing a wait, we'd need a ready flag though + // ... for sender's thread start + + /** + * Wake up all threads waiting on this event + * (if any, and if so it would only be the sender) + */ + sendEvent.notifyAll(); } @@ -84,6 +92,11 @@ public final class SenderThread : Thread /* TODO: handle normal messages (xCount with fakeLagInBetween) */ + // TODO: See above notes about libsnooze behaviour due + // ... to usage in our context + sendEvent.wait(); // TODO: Catch any exceptions from libsnooze + + /* Lock queue */ sendQueueLock.lock(); @@ -98,9 +111,13 @@ public final class SenderThread : Thread /* Unlock queue */ sendQueueLock.unlock(); - - /* TODO: Yield */ - Thread.yield(); } } + + public void end() + { + // TODO: See above notes about libsnooze behaviour due + // ... to usage in our context + sendEvent.notifyAll(); + } } \ No newline at end of file