From 4becdfa125b07ff969d6540e1112735b53cd15eb Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 18 Mar 2013 08:12:31 +0100 Subject: Fix RecursiveLockImpl* corner case: Timeout reached but lock released -> Assume Lock If timeout has been reached but the lock has been released, the lock has to be assumed. --- .../util/locks/RecursiveLockImpl01Unfairish.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/java/jogamp/common/util/locks/RecursiveLockImpl01Unfairish.java') diff --git a/src/java/jogamp/common/util/locks/RecursiveLockImpl01Unfairish.java b/src/java/jogamp/common/util/locks/RecursiveLockImpl01Unfairish.java index 5b5e42e..e8fecb1 100644 --- a/src/java/jogamp/common/util/locks/RecursiveLockImpl01Unfairish.java +++ b/src/java/jogamp/common/util/locks/RecursiveLockImpl01Unfairish.java @@ -107,11 +107,12 @@ public class RecursiveLockImpl01Unfairish implements RecursiveLock { @Override public final void decrQSz() { qsz--; } - // lock count by same thread - private int holdCount = 0; - // stack trace of the lock, only used if DEBUG - private Throwable lockedStack = null; + /** lock count by same thread */ + private int holdCount = 0; + /** queue size of waiting threads */ private int qsz = 0; + /** stack trace of the lock, only used if DEBUG */ + private Throwable lockedStack = null; } protected final Sync sync; @@ -207,7 +208,7 @@ public class RecursiveLockImpl01Unfairish implements RecursiveLock { synchronized(sync) { final Thread cur = Thread.currentThread(); if(TRACE_LOCK) { - System.err.println("+++ LOCK 0 "+toString()+", cur "+threadName(cur)); + System.err.println("+++ LOCK 0 "+toString()+", timeout "+timeout+" ms, cur "+threadName(cur)); } if (sync.isOwner(cur)) { sync.incrHoldCount(cur); @@ -221,6 +222,9 @@ public class RecursiveLockImpl01Unfairish implements RecursiveLock { if ( 0 >= timeout ) { // locked by other thread and no waiting requested + if(TRACE_LOCK) { + System.err.println("+++ LOCK XY "+toString()+", cur "+threadName(cur)+", left "+timeout+" ms"); + } return false; } @@ -232,9 +236,9 @@ public class RecursiveLockImpl01Unfairish implements RecursiveLock { } while (null != sync.getOwner() && 0 < timeout) ; sync.decrQSz(); - if( 0 >= timeout ) { + if( 0 >= timeout && sync.getOwner() != null ) { // timed out - if(TRACE_LOCK || DEBUG) { + if(TRACE_LOCK) { System.err.println("+++ LOCK XX "+toString()+", cur "+threadName(cur)+", left "+timeout+" ms"); } return false; -- cgit v1.2.3