diff options
author | Mark Spruiell <mes@zeroc.com> | 2002-12-05 00:18:28 +0000 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2002-12-05 00:18:28 +0000 |
commit | db3284e2a762e2ca1bec7002e25221e0199ab66a (patch) | |
tree | d70aaada0e771af13bf19b784e8ebc8c5f1a7a49 /java/src | |
parent | increase Glacier's server thread pool size to avoid a deadlock due to IceJ (diff) | |
download | ice-db3284e2a762e2ca1bec7002e25221e0199ab66a.tar.bz2 ice-db3284e2a762e2ca1bec7002e25221e0199ab66a.tar.xz ice-db3284e2a762e2ca1bec7002e25221e0199ab66a.zip |
yet another fix for Incoming cache
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/IceInternal/Connection.java | 82 | ||||
-rw-r--r-- | java/src/IceInternal/Incoming.java | 35 |
2 files changed, 56 insertions, 61 deletions
diff --git a/java/src/IceInternal/Connection.java b/java/src/IceInternal/Connection.java index fa44610a7aa..f34f167b245 100644 --- a/java/src/IceInternal/Connection.java +++ b/java/src/IceInternal/Connection.java @@ -611,9 +611,9 @@ public final class Connection extends EventHandler } catch(Ice.LocalException ex) { - _mutex.lock(); - reclaimIncoming(in); + reclaimIncoming(in); // Must be called outside of synchronization on _mutex. in = null; + _mutex.lock(); try { setState(StateClosed, ex); @@ -666,11 +666,6 @@ public final class Connection extends EventHandler } finally { - if(in != null) - { - reclaimIncoming(in); - in = null; - } _mutex.unlock(); } } @@ -679,9 +674,7 @@ public final class Connection extends EventHandler { if(in != null) { - _mutex.lock(); - reclaimIncoming(in); - _mutex.unlock(); + reclaimIncoming(in); // Must be called outside of synchronization on _mutex. } } } @@ -908,14 +901,7 @@ public final class Connection extends EventHandler registerWithPool(); } unregisterWithPool(); - // - // The cache of Incoming objects must be destroyed - // outside the synchronization on _mutex to avoid - // a potential deadlock with ObjectAdapter. - // - Incoming cache = _incomingCache; - _incomingCache = null; - new DestroyIncomingThread(cache).start(); + destroyIncomingCache(); break; } } @@ -1024,49 +1010,54 @@ public final class Connection extends EventHandler private Incoming getIncoming() { - Incoming in; - if(_incomingCache == null) - { - in = new Incoming(_instance, _adapter); - } - else + Incoming in = null; + + synchronized(_incomingCacheMutex) { - in = _incomingCache; - _incomingCache = _incomingCache.next; - in.next = null; - in.reset(_adapter); + if(_incomingCache == null) + { + in = new Incoming(_instance, _adapter); + } + else + { + in = _incomingCache; + _incomingCache = _incomingCache.next; + in.next = null; + in.reset(_adapter); + } } + return in; } private void reclaimIncoming(Incoming in) { - in.next = _incomingCache; - _incomingCache = in; + in.finished(); + + synchronized(_incomingCacheMutex) + { + in.next = _incomingCache; + _incomingCache = in; + } } - // - // Must be called outside of synchronization on _mutex. - // - private static class DestroyIncomingThread extends Thread + private void + destroyIncomingCache() { - DestroyIncomingThread(Incoming cache) + Incoming in = null; + + synchronized(_incomingCacheMutex) { - _cache = cache; + in = _incomingCache; + _incomingCache = null; } - public void - run() + while(in != null) { - while(_cache != null) - { - _cache.destroy(); - _cache = _cache.next; - } + in.destroy(); + in = in.next; } - - private Incoming _cache; } private final Transceiver _transceiver; @@ -1087,4 +1078,5 @@ public final class Connection extends EventHandler private boolean _registeredWithPool; private RecursiveMutex _mutex = new RecursiveMutex(); private Incoming _incomingCache; + private java.lang.Object _incomingCacheMutex = new java.lang.Object(); } diff --git a/java/src/IceInternal/Incoming.java b/java/src/IceInternal/Incoming.java index 5210b0d80b3..d9c1d389e37 100644 --- a/java/src/IceInternal/Incoming.java +++ b/java/src/IceInternal/Incoming.java @@ -33,6 +33,20 @@ public class Incoming } // + // Must be called immediately after this object is no longer + // needed, in order to update the object adapter usage count. + // + public void + finished() + { + if(_current.adapter != null) + { + ((Ice.ObjectAdapterI)(_current.adapter)).decUsageCount(); + _current.adapter = null; + } + } + + // // This function allows this object to be reused, rather than // reallocated. // @@ -46,19 +60,13 @@ public class Incoming _current.ctx.clear(); } - if(_current.adapter != adapter) - { - if(_current.adapter != null) - { - ((Ice.ObjectAdapterI)(_current.adapter)).decUsageCount(); - } + //assert(_current.adapter == null); // finished() should have been called - _current.adapter = adapter; + _current.adapter = adapter; - if(_current.adapter != null) - { - ((Ice.ObjectAdapterI)(_current.adapter)).incUsageCount(); - } + if(_current.adapter != null) + { + ((Ice.ObjectAdapterI)(_current.adapter)).incUsageCount(); } } @@ -70,11 +78,6 @@ public class Incoming { _is.destroy(); _os.destroy(); - - if(_current.adapter != null) - { - ((Ice.ObjectAdapterI)(_current.adapter)).decUsageCount(); - } } public void |