summaryrefslogtreecommitdiff
path: root/jurt/com/sun/star
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2015-10-15 09:43:06 +0200
committerNoel Grandin <noel@peralex.com>2015-10-15 11:28:09 +0200
commit846135c4c9eaedd18b2e01826860337c1b269664 (patch)
treec11493a25c16a6a683aa6a7a18c105d9946e88ee /jurt/com/sun/star
parent874122a6663c92df5b0441355b17c596bb524b06 (diff)
use AtomicInteger for _life_count
(cid#1326323 Unguarded read) Just switch this to an AtomicInteger, it's cheaper, and doesn't require synchronization, so less chance of a deadlock. This is an API change since this is a protected field in a public class, but anyone messing with the internals of this class should have known better. Change-Id: Idafc760c2e9d83442b8209ad23d180acb8dccb20
Diffstat (limited to 'jurt/com/sun/star')
-rw-r--r--jurt/com/sun/star/lib/uno/bridges/java_remote/java_remote_bridge.java35
1 files changed, 16 insertions, 19 deletions
diff --git a/jurt/com/sun/star/lib/uno/bridges/java_remote/java_remote_bridge.java b/jurt/com/sun/star/lib/uno/bridges/java_remote/java_remote_bridge.java
index 0dcc75d91bd2..c949b5598e16 100644
--- a/jurt/com/sun/star/lib/uno/bridges/java_remote/java_remote_bridge.java
+++ b/jurt/com/sun/star/lib/uno/bridges/java_remote/java_remote_bridge.java
@@ -26,33 +26,34 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
-import com.sun.star.lib.util.DisposeListener;
-import com.sun.star.lib.util.DisposeNotifier;
import com.sun.star.bridge.XBridge;
import com.sun.star.bridge.XInstanceProvider;
import com.sun.star.connection.XConnection;
+import com.sun.star.lang.DisposedException;
import com.sun.star.lang.EventObject;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XEventListener;
-import com.sun.star.lang.DisposedException;
import com.sun.star.lib.uno.environments.java.java_environment;
import com.sun.star.lib.uno.environments.remote.IProtocol;
import com.sun.star.lib.uno.environments.remote.IReceiver;
+import com.sun.star.lib.uno.environments.remote.IThreadPool;
import com.sun.star.lib.uno.environments.remote.Job;
import com.sun.star.lib.uno.environments.remote.Message;
import com.sun.star.lib.uno.environments.remote.ThreadId;
import com.sun.star.lib.uno.environments.remote.ThreadPoolManager;
-import com.sun.star.lib.uno.environments.remote.IThreadPool;
import com.sun.star.lib.uno.typedesc.MethodDescription;
import com.sun.star.lib.uno.typedesc.TypeDescription;
+import com.sun.star.lib.util.DisposeListener;
+import com.sun.star.lib.util.DisposeNotifier;
+import com.sun.star.uno.Any;
import com.sun.star.uno.IBridge;
import com.sun.star.uno.IEnvironment;
-import com.sun.star.uno.UnoRuntime;
-import com.sun.star.uno.XInterface;
import com.sun.star.uno.Type;
import com.sun.star.uno.TypeClass;
-import com.sun.star.uno.Any;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XInterface;
/**
* This class implements a remote bridge.
@@ -156,7 +157,7 @@ public class java_remote_bridge
protected IProtocol _iProtocol;
protected IEnvironment _java_environment;
protected MessageDispatcher _messageDispatcher;
- protected int _life_count = 0; // determines if this bridge is alive, which is controlled by acquire and release calls
+ protected final AtomicInteger _life_count = new AtomicInteger(); // determines if this bridge is alive, which is controlled by acquire and release calls
private final ArrayList<XEventListener> _listeners = new ArrayList<XEventListener>();
@@ -169,7 +170,7 @@ public class java_remote_bridge
* This method is for testing only.
*/
int getLifeCount() {
- return _life_count;
+ return _life_count.get();
}
/**
@@ -447,10 +448,10 @@ public class java_remote_bridge
*
* @see com.sun.star.uno.IBridge#acquire
*/
- public synchronized void acquire() {
- ++ _life_count;
+ public void acquire() {
+ int x = _life_count.incrementAndGet();
- if(DEBUG) System.err.println("##### " + getClass().getName() + ".acquire:" + _life_count);
+ if(DEBUG) System.err.println("##### " + getClass().getName() + ".acquire:" + x);
}
/**
@@ -461,12 +462,8 @@ public class java_remote_bridge
* @see com.sun.star.uno.IBridge#release
*/
public void release() {
- boolean dispose;
- synchronized (this) {
- --_life_count;
- dispose = _life_count <= 0;
- }
- if (dispose) {
+ int x = _life_count.decrementAndGet();
+ if (x <= 0) {
dispose(new Throwable("end of life"));
}
}
@@ -521,7 +518,7 @@ public class java_remote_bridge
proxyFactory.dispose();
if (DEBUG) {
- if (_life_count != 0) {
+ if (_life_count.get() != 0) {
System.err.println(getClass().getName()
+ ".dispose - life count (proxies left):"
+ _life_count);