diff options
author | Sven Gothel <[email protected]> | 2014-08-29 16:11:08 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-08-29 16:11:08 +0200 |
commit | dfb9ed47ac6d8e85f6ae5fe166e7a6e28ca8ff83 (patch) | |
tree | 7a5d5ffff61a7eac3e04ff4ee4cb00b4c3437998 /src/jogl | |
parent | ad79bd072b600a3f2416cc6f0c61e2925000069d (diff) |
Bug 1054: Cleanup GLContext: 'lock' -> 'contextLock'
Diffstat (limited to 'src/jogl')
-rw-r--r-- | src/jogl/classes/javax/media/opengl/GLContext.java | 2 | ||||
-rw-r--r-- | src/jogl/classes/jogamp/opengl/GLContextImpl.java | 66 | ||||
-rw-r--r-- | src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java | 4 |
3 files changed, 36 insertions, 36 deletions
diff --git a/src/jogl/classes/javax/media/opengl/GLContext.java b/src/jogl/classes/javax/media/opengl/GLContext.java index 863eb1a1e..e10579df1 100644 --- a/src/jogl/classes/javax/media/opengl/GLContext.java +++ b/src/jogl/classes/javax/media/opengl/GLContext.java @@ -205,7 +205,7 @@ public abstract class GLContext { private final HashMap<String, Object> attachedObjects = new HashMap<String, Object>(); // RecursiveLock maintains a queue of waiting Threads, ensuring the longest waiting thread will be notified at unlock. - protected final RecursiveLock lock = LockFactory.createRecursiveLock(); + protected final RecursiveLock contextLock = LockFactory.createRecursiveLock(); /** The underlying native OpenGL context */ protected volatile long contextHandle; // volatile: avoid locking for read-only access diff --git a/src/jogl/classes/jogamp/opengl/GLContextImpl.java b/src/jogl/classes/jogamp/opengl/GLContextImpl.java index 7c88a2c33..c5a125a1e 100644 --- a/src/jogl/classes/jogamp/opengl/GLContextImpl.java +++ b/src/jogl/classes/jogamp/opengl/GLContextImpl.java @@ -197,11 +197,11 @@ public abstract class GLContextImpl extends GLContext { throw new GLException("Setting read drawable feature not available"); } final Thread currentThread = Thread.currentThread(); - if( lock.isLockedByOtherThread() ) { - throw new GLException("GLContext current by other thread "+lock.getOwner().getName()+", operation not allowed on this thread "+currentThread.getName()); + if( contextLock.isLockedByOtherThread() ) { + throw new GLException("GLContext current by other thread "+contextLock.getOwner().getName()+", operation not allowed on this thread "+currentThread.getName()); } - final boolean lockHeld = lock.isOwner(currentThread); - if( lockHeld && lock.getHoldCount() > 1 ) { + final boolean lockHeld = contextLock.isOwner(currentThread); + if( lockHeld && contextLock.getHoldCount() > 1 ) { // would need to makeCurrent * holdCount throw new GLException("GLContext is recursively locked - unsupported for setGLDrawable(..)"); } @@ -225,11 +225,11 @@ public abstract class GLContextImpl extends GLContext { public final GLDrawable setGLDrawable(final GLDrawable readWrite, final boolean setWriteOnly) { // Validate constraints first! final Thread currentThread = Thread.currentThread(); - if( lock.isLockedByOtherThread() ) { - throw new GLException("GLContext current by other thread "+lock.getOwner().getName()+", operation not allowed on this thread "+currentThread.getName()); + if( contextLock.isLockedByOtherThread() ) { + throw new GLException("GLContext current by other thread "+contextLock.getOwner().getName()+", operation not allowed on this thread "+currentThread.getName()); } - final boolean lockHeld = lock.isOwner(currentThread); - if( lockHeld && lock.getHoldCount() > 1 ) { + final boolean lockHeld = contextLock.isOwner(currentThread); + if( lockHeld && contextLock.getHoldCount() > 1 ) { // would need to makeCurrent * holdCount throw new GLException("GLContext is recursively locked - unsupported for setGLDrawable(..)"); } @@ -330,11 +330,11 @@ public abstract class GLContextImpl extends GLContext { private void release(final boolean inDestruction) throws GLException { if( TRACE_SWITCH ) { final long drawH = null != drawable ? drawable.getHandle() : 0; - System.err.println(getThreadName() +": GLContext.ContextSwitch[release.0]: obj " + toHexString(hashCode()) + ", ctx "+toHexString(contextHandle)+", surf "+(null!=drawable)+" "+toHexString(drawH)+", inDestruction: "+inDestruction+", "+lock); + System.err.println(getThreadName() +": GLContext.ContextSwitch[release.0]: obj " + toHexString(hashCode()) + ", ctx "+toHexString(contextHandle)+", surf "+(null!=drawable)+" "+toHexString(drawH)+", inDestruction: "+inDestruction+", "+contextLock); } - if ( !lock.isOwner(Thread.currentThread()) ) { + if ( !contextLock.isOwner(Thread.currentThread()) ) { final long drawH = null != drawable ? drawable.getHandle() : 0; - final String msg = getThreadName() +": Context not current on thread, obj " + toHexString(hashCode())+", ctx "+toHexString(contextHandle)+", surf "+(null!=drawable)+" "+toHexString(drawH)+", inDestruction: "+inDestruction+", "+lock; + final String msg = getThreadName() +": Context not current on thread, obj " + toHexString(hashCode())+", ctx "+toHexString(contextHandle)+", surf "+(null!=drawable)+" "+toHexString(drawH)+", inDestruction: "+inDestruction+", "+contextLock; if( DEBUG_TRACE_SWITCH ) { System.err.println(msg); if( null != lastCtxReleaseStack ) { @@ -348,7 +348,7 @@ public abstract class GLContextImpl extends GLContext { } Throwable drawableContextMadeCurrentException = null; - final boolean actualRelease = ( inDestruction || lock.getHoldCount() == 1 ) && 0 != contextHandle; + final boolean actualRelease = ( inDestruction || contextLock.getHoldCount() == 1 ) && 0 != contextHandle; try { if( actualRelease ) { if( !inDestruction ) { @@ -366,9 +366,9 @@ public abstract class GLContextImpl extends GLContext { setCurrent(null); } drawable.unlockSurface(); - lock.unlock(); + contextLock.unlock(); if( DEBUG_TRACE_SWITCH ) { - final String msg = getThreadName() +": GLContext.ContextSwitch[release.X]: obj " + toHexString(hashCode()) + ", ctx "+toHexString(contextHandle)+", surf "+toHexString(drawable.getHandle())+" - "+(actualRelease?"switch":"keep ")+" - "+lock; + final String msg = getThreadName() +": GLContext.ContextSwitch[release.X]: obj " + toHexString(hashCode()) + ", ctx "+toHexString(contextHandle)+", surf "+toHexString(drawable.getHandle())+" - "+(actualRelease?"switch":"keep ")+" - "+contextLock; lastCtxReleaseStack = new Throwable(msg); if( TRACE_SWITCH ) { System.err.println(msg); @@ -388,7 +388,7 @@ public abstract class GLContextImpl extends GLContext { if ( DEBUG_TRACE_SWITCH ) { final long drawH = null != drawable ? drawable.getHandle() : 0; System.err.println(getThreadName() + ": GLContextImpl.destroy.0: obj " + toHexString(hashCode()) + ", ctx " + toHexString(contextHandle) + - ", surf "+(null!=drawable)+" "+toHexString(drawH)+", isShared "+GLContextShareSet.isShared(this)+" - "+lock); + ", surf "+(null!=drawable)+" "+toHexString(drawH)+", isShared "+GLContextShareSet.isShared(this)+" - "+contextLock); } if ( 0 != contextHandle ) { // isCreated() ? if ( null == drawable ) { @@ -406,17 +406,17 @@ public abstract class GLContextImpl extends GLContext { } // Must hold the lock around the destroy operation to make sure we // don't destroy the context while another thread renders to it. - lock.lock(); // holdCount++ -> 1 - n (1: not locked, 2-n: destroy while rendering) + contextLock.lock(); // holdCount++ -> 1 - n (1: not locked, 2-n: destroy while rendering) if ( DEBUG_TRACE_SWITCH ) { - if ( lock.getHoldCount() > 2 ) { + if ( contextLock.getHoldCount() > 2 ) { final String msg = getThreadName() + ": GLContextImpl.destroy: obj " + toHexString(hashCode()) + ", ctx " + toHexString(contextHandle); - System.err.println(msg+" - Lock was hold more than once - makeCurrent/release imbalance: "+lock); + System.err.println(msg+" - Lock was hold more than once - makeCurrent/release imbalance: "+contextLock); Thread.dumpStack(); } } try { // if not current, makeCurrent(), to call associateDrawable(..) and to disable debug handler - if ( lock.getHoldCount() == 1 ) { + if ( contextLock.getHoldCount() == 1 ) { if ( GLContext.CONTEXT_NOT_CURRENT == makeCurrent() ) { throw new GLException("GLContext.makeCurrent() failed: "+toString()); } @@ -434,7 +434,7 @@ public abstract class GLContextImpl extends GLContext { defaultVAO = 0; } glDebugHandler.enable(false); - if(lock.getHoldCount() > 1) { + if(contextLock.getHoldCount() > 1) { // pending release() after makeCurrent() release(true); } @@ -447,10 +447,10 @@ public abstract class GLContextImpl extends GLContext { } resetStates(false); } finally { - lock.unlock(); + contextLock.unlock(); if ( DEBUG_TRACE_SWITCH ) { System.err.println(getThreadName() + ": GLContextImpl.destroy.X: obj " + toHexString(hashCode()) + ", ctx " + toHexString(contextHandle) + - ", isShared "+GLContextShareSet.isShared(this)+" - "+lock); + ", isShared "+GLContextShareSet.isShared(this)+" - "+contextLock); } } } finally { @@ -536,11 +536,11 @@ public abstract class GLContextImpl extends GLContext { final boolean hasDrawable = null != drawable; if( TRACE_SWITCH ) { final long drawH = null != drawable ? drawable.getHandle() : 0; - System.err.println(getThreadName() +": GLContext.ContextSwitch[makeCurrent.0]: obj " + toHexString(hashCode()) + ", ctx "+toHexString(contextHandle)+", surf "+hasDrawable+" "+toHexString(drawH)+" - "+lock); + System.err.println(getThreadName() +": GLContext.ContextSwitch[makeCurrent.0]: obj " + toHexString(hashCode()) + ", ctx "+toHexString(contextHandle)+", surf "+hasDrawable+" "+toHexString(drawH)+" - "+contextLock); } if( !hasDrawable ) { if( DEBUG_TRACE_SWITCH ) { - System.err.println(getThreadName() +": GLContext.ContextSwitch[makeCurrent.X0]: obj " + toHexString(hashCode()) + ", ctx "+toHexString(contextHandle)+" - NULL Drawable - CONTEXT_NOT_CURRENT - "+lock); + System.err.println(getThreadName() +": GLContext.ContextSwitch[makeCurrent.X0]: obj " + toHexString(hashCode()) + ", ctx "+toHexString(contextHandle)+" - NULL Drawable - CONTEXT_NOT_CURRENT - "+contextLock); } return CONTEXT_NOT_CURRENT; } @@ -548,7 +548,7 @@ public abstract class GLContextImpl extends GLContext { final int lockRes = drawable.lockSurface(); if (NativeSurface.LOCK_SURFACE_NOT_READY >= lockRes) { if( DEBUG_TRACE_SWITCH ) { - System.err.println(getThreadName() +": GLContext.ContextSwitch[makeCurrent.X1]: obj " + toHexString(hashCode()) + ", ctx "+toHexString(contextHandle)+", surf "+toHexString(drawable.getHandle())+" - Surface Not Ready - CONTEXT_NOT_CURRENT - "+lock); + System.err.println(getThreadName() +": GLContext.ContextSwitch[makeCurrent.X1]: obj " + toHexString(hashCode()) + ", ctx "+toHexString(contextHandle)+", surf "+toHexString(drawable.getHandle())+" - Surface Not Ready - CONTEXT_NOT_CURRENT - "+contextLock); } return CONTEXT_NOT_CURRENT; } @@ -560,7 +560,7 @@ public abstract class GLContextImpl extends GLContext { if ( 0 == drawable.getHandle() ) { throw new GLException("drawable has invalid handle: "+drawable); } - lock.lock(); + contextLock.lock(); try { // One context can only be current by one thread, // and one thread can only have one context current! @@ -572,7 +572,7 @@ public abstract class GLContextImpl extends GLContext { drawableUpdatedNotify(); unlockResources = false; // success if( TRACE_SWITCH ) { - System.err.println(getThreadName() +": GLContext.ContextSwitch[makeCurrent.X2]: obj " + toHexString(hashCode()) + ", ctx "+toHexString(contextHandle)+", surf "+toHexString(drawable.getHandle())+" - keep - CONTEXT_CURRENT - "+lock); + System.err.println(getThreadName() +": GLContext.ContextSwitch[makeCurrent.X2]: obj " + toHexString(hashCode()) + ", ctx "+toHexString(contextHandle)+", surf "+toHexString(drawable.getHandle())+" - keep - CONTEXT_CURRENT - "+contextLock); } return CONTEXT_CURRENT; } else { @@ -595,9 +595,9 @@ public abstract class GLContextImpl extends GLContext { } finally { if (unlockResources) { if( DEBUG_TRACE_SWITCH ) { - System.err.println(getThreadName() +": GLContext.ContextSwitch[makeCurrent.1]: Context lock.unlock() due to error, res "+makeCurrentResultToString(res)+", "+lock); + System.err.println(getThreadName() +": GLContext.ContextSwitch[makeCurrent.1]: Context lock.unlock() due to error, res "+makeCurrentResultToString(res)+", "+contextLock); } - lock.unlock(); + contextLock.unlock(); } } } /* if ( drawable.isRealized() ) */ @@ -648,7 +648,7 @@ public abstract class GLContextImpl extends GLContext { */ } if( TRACE_SWITCH ) { - System.err.println(getThreadName() +": GLContext.ContextSwitch[makeCurrent.X3]: obj " + toHexString(hashCode()) + ", ctx "+toHexString(contextHandle)+", surf "+toHexString(drawable.getHandle())+" - switch - "+makeCurrentResultToString(res)+" - stateTracker.on "+glStateTracker.isEnabled()+" - "+lock); + System.err.println(getThreadName() +": GLContext.ContextSwitch[makeCurrent.X3]: obj " + toHexString(hashCode()) + ", ctx "+toHexString(contextHandle)+", surf "+toHexString(drawable.getHandle())+" - switch - "+makeCurrentResultToString(res)+" - stateTracker.on "+glStateTracker.isEnabled()+" - "+contextLock); } return res; } @@ -2210,7 +2210,7 @@ public abstract class GLContextImpl extends GLContext { * </p> */ public final boolean isOwner(final Thread thread) { - return lock.isOwner(thread); + return contextLock.isOwner(thread); } /** @@ -2220,7 +2220,7 @@ public abstract class GLContextImpl extends GLContext { * </p> */ public final boolean hasWaiters() { - return lock.getQueueLength()>0; + return contextLock.getQueueLength()>0; } /** @@ -2230,7 +2230,7 @@ public abstract class GLContextImpl extends GLContext { * </p> */ public final int getLockCount() { - return lock.getHoldCount(); + return contextLock.getHoldCount(); } //--------------------------------------------------------------------------- diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java index 7066a6db5..ddfa873ae 100644 --- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java @@ -726,7 +726,7 @@ public class MacOSXCGLContext extends GLContextImpl final RecursiveLock surfaceLock = ols.getLock(); if( surfaceLock.tryLock( maxwait ) ) { try { - if( MacOSXCGLContext.this.lock.tryLock( maxwait ) ) { + if( MacOSXCGLContext.this.contextLock.tryLock( maxwait ) ) { try { nsOpenGLLayer = CGL.createNSOpenGLLayer(ctx, shaderProgram, pfmt, pbuffer, texID, isOpaque, texWidth, texHeight, winWidth, winHeight); @@ -739,7 +739,7 @@ public class MacOSXCGLContext extends GLContextImpl System.err.println("NSOpenGLLayer.Attach: OK, layer "+toHexString(nsOpenGLLayer)+" w/ pbuffer "+toHexString(pbuffer)+", texID "+texID+", texSize "+lastWidth+"x"+lastHeight+", drawableHandle "+toHexString(drawable.getHandle())+" - "+getThreadName()); } } finally { - MacOSXCGLContext.this.lock.unlock(); + MacOSXCGLContext.this.contextLock.unlock(); } } } finally { |