diff options
author | Sven Gothel <[email protected]> | 2011-11-26 06:13:27 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-11-26 06:13:27 +0100 |
commit | 3f790b11166f5c51773a9b8832478feb3dcf8a40 (patch) | |
tree | 6378b10bda5ae14d731a9e20d5117263de21c018 | |
parent | 5866e08bdff712afed19a206a58f872e0f88c827 (diff) |
DefaultGraphicsDevice: Initialize toolkitLock directly in cstr, where setToolkitLock(..) swaps the lock thread safe.
-rw-r--r-- | src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsDevice.java | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsDevice.java index b419fb29b..331167244 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsDevice.java +++ b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsDevice.java @@ -55,7 +55,7 @@ public class DefaultGraphicsDevice implements Cloneable, AbstractGraphicsDevice this.unitID = unitID; this.uniqueID = getUniqueID(type, connection, unitID); this.handle = 0; - setToolkitLock( NativeWindowFactory.getDefaultToolkitLock(type) ); + this.toolkitLock = NativeWindowFactory.getDefaultToolkitLock(type); } /** @@ -70,7 +70,7 @@ public class DefaultGraphicsDevice implements Cloneable, AbstractGraphicsDevice this.unitID = unitID; this.uniqueID = getUniqueID(type, connection, unitID); this.handle = handle; - setToolkitLock( NativeWindowFactory.createDefaultToolkitLock(type, handle) ); + this.toolkitLock = NativeWindowFactory.createDefaultToolkitLock(type, handle); } /** @@ -85,7 +85,7 @@ public class DefaultGraphicsDevice implements Cloneable, AbstractGraphicsDevice this.unitID = unitID; this.uniqueID = getUniqueID(type, connection, unitID); this.handle = handle; - setToolkitLock( locker ); + this.toolkitLock = null != locker ? locker : NativeWindowFactoryImpl.getNullToolkitLock(); } @Override @@ -152,10 +152,21 @@ public class DefaultGraphicsDevice implements Cloneable, AbstractGraphicsDevice * Set the internal ToolkitLock, which is used within the * {@link #lock()} and {@link #unlock()} implementation. * + * <p> + * The current ToolkitLock is being locked/unlocked while swapping the reference, + * ensuring no concurrent access can occur during the swap. + * </p> + * * @param locker the ToolkitLock, if null, {@link jogamp.nativewindow.NullToolkitLock} is being used */ protected void setToolkitLock(ToolkitLock locker) { - this.toolkitLock = ( null == locker ) ? NativeWindowFactoryImpl.getNullToolkitLock() : locker ; + final ToolkitLock _toolkitLock = toolkitLock; + _toolkitLock.lock(); + try { + toolkitLock = ( null == locker ) ? NativeWindowFactoryImpl.getNullToolkitLock() : locker ; + } finally { + _toolkitLock.unlock(); + } } /** |