diff options
author | Sven Gothel <[email protected]> | 2014-07-08 10:50:52 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-07-08 10:50:52 +0200 |
commit | 7d0c81f28d44179c7dafeeff1f3787f8aec622aa (patch) | |
tree | 3edffe7baa88738f1763d7cb446c72f0d755901e /src/nativewindow/classes/jogamp | |
parent | 73d2a436f92e360126167d9ce09b3d9637204921 (diff) |
Findbugs.increment_volatile: Use AtomicInteger or add comment that operation is safe!
Diffstat (limited to 'src/nativewindow/classes/jogamp')
-rw-r--r-- | src/nativewindow/classes/jogamp/nativewindow/SharedResourceToolkitLock.java | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/nativewindow/classes/jogamp/nativewindow/SharedResourceToolkitLock.java b/src/nativewindow/classes/jogamp/nativewindow/SharedResourceToolkitLock.java index d0174b2f5..5dac74323 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/SharedResourceToolkitLock.java +++ b/src/nativewindow/classes/jogamp/nativewindow/SharedResourceToolkitLock.java @@ -29,6 +29,7 @@ package jogamp.nativewindow; import java.util.Iterator; +import java.util.concurrent.atomic.AtomicInteger; import javax.media.nativewindow.ToolkitLock; @@ -86,11 +87,11 @@ public class SharedResourceToolkitLock implements ToolkitLock { res = (SharedResourceToolkitLock) handle2Lock.get(handle); if( null == res ) { res = new SharedResourceToolkitLock(handle); - res.refCount++; + res.refCount.incrementAndGet(); handle2Lock.put(handle, res); if(DEBUG || TRACE_LOCK) { System.err.println("SharedResourceToolkitLock.get() * NEW *: "+res); } } else { - res.refCount++; + res.refCount.incrementAndGet(); if(DEBUG || TRACE_LOCK) { System.err.println("SharedResourceToolkitLock.get() * EXIST *: "+res); } } } @@ -99,12 +100,12 @@ public class SharedResourceToolkitLock implements ToolkitLock { private final RecursiveLock lock; private final long handle; - private volatile int refCount; + private final AtomicInteger refCount; private SharedResourceToolkitLock(final long handle) { this.lock = LockFactory.createRecursiveLock(); this.handle = handle; - this.refCount = 0; + this.refCount = new AtomicInteger(0); } @@ -127,10 +128,9 @@ public class SharedResourceToolkitLock implements ToolkitLock { @Override public final void dispose() { - if(0 < refCount) { // volatile OK + if(0 < refCount.get()) { // volatile OK synchronized(handle2Lock) { - refCount--; - if(0 == refCount) { + if( 0 == refCount.decrementAndGet() ) { if(DEBUG || TRACE_LOCK) { System.err.println("SharedResourceToolkitLock.dispose() * REMOV *: "+this); } handle2Lock.remove(handle); } else { |