From c54b158abd24d72c239941f2fa11d2c0c8b2cbe4 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Fri, 23 Aug 2013 10:29:48 -0700 Subject: [PATCH] Notify client observers directly if we're already on the RunQueue thread. This avoids a needless wait in the run queue for most notifications. Only notifications that result directly from something one of the communicator threads did will need to do a loop de loop. This should close the hole where ClientObserver could be told that the ClientObject was available *after* some events have come in on the ClientObject (which they then miss). Now when the subscription response comes in for the ClientObject, observers are notified immediately, and will be wired up and ready for any messages that are themselves already in the queue ready to be dispatched. --- .../main/java/com/threerings/presents/client/Client.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/threerings/presents/client/Client.java b/core/src/main/java/com/threerings/presents/client/Client.java index be86e33b3..4c875735b 100644 --- a/core/src/main/java/com/threerings/presents/client/Client.java +++ b/core/src/main/java/com/threerings/presents/client/Client.java @@ -879,9 +879,13 @@ public class Client protected void notifyObservers (final ObserverOps.Session op) { - if (_runQueue == null) { + // if we have no run queue, or we're already on the run queue's thread; dispatch this + // operation immediately on the current thread + if (_runQueue == null || _runQueue.isDispatchThread()) { _observers.apply(op); - } else { + } + // otherwise queue this notification up to run on the run queue thread + else { _runQueue.postRunnable(new Runnable() { public void run () { _observers.apply(op);