mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-30 08:34:16 +01:00
reduce the length of the sleep when waiting for lock; add code to
capture stack trace at lock time that'll be printed out along with the current thread's trace when I can't get a lock in one second. I'll comment that out shortly but want it for debugging -- though it's untested: can't repro any failure to lock now.
This commit is contained in:
parent
2b28a4d27c
commit
4cdafbd510
1 changed files with 12 additions and 1 deletions
|
@ -48,6 +48,7 @@ public class GameUtils {
|
|||
private String m_path;
|
||||
private boolean m_isForWrite;
|
||||
private int m_lockCount;
|
||||
StackTraceElement[] m_lockTrace;
|
||||
|
||||
// This will leak empty ReentrantReadWriteLock instances for
|
||||
// now.
|
||||
|
@ -75,6 +76,11 @@ public class GameUtils {
|
|||
s_locks.put( m_path, this );
|
||||
++m_lockCount;
|
||||
gotIt = true;
|
||||
|
||||
StackTraceElement[] trace = Thread.currentThread().
|
||||
getStackTrace();
|
||||
m_lockTrace = new StackTraceElement[trace.length];
|
||||
System.arraycopy( trace, 0, m_lockTrace, 0, trace.length );
|
||||
} else if ( this == owner && ! m_isForWrite ) {
|
||||
Assert.assertTrue( 0 == m_lockCount );
|
||||
++m_lockCount;
|
||||
|
@ -86,6 +92,7 @@ public class GameUtils {
|
|||
|
||||
public GameLock lock()
|
||||
{
|
||||
long stopTime = System.currentTimeMillis() + 1000;
|
||||
Utils.logf( "GameLock.lock(%s)", m_path );
|
||||
// Utils.printStack();
|
||||
for ( ; ; ) {
|
||||
|
@ -95,11 +102,15 @@ public class GameUtils {
|
|||
Utils.logf( "GameLock.lock() failed; sleeping" );
|
||||
// Utils.printStack();
|
||||
try {
|
||||
Thread.sleep( 100 ); // milliseconds
|
||||
Thread.sleep( 25 ); // milliseconds
|
||||
} catch( InterruptedException ie ) {
|
||||
Utils.logf( "GameLock.lock(): %s", ie.toString() );
|
||||
break;
|
||||
}
|
||||
if ( System.currentTimeMillis() >= stopTime ) {
|
||||
Utils.printStack( m_lockTrace );
|
||||
Assert.fail();
|
||||
}
|
||||
}
|
||||
Utils.logf( "GameLock.lock(%s) done", m_path );
|
||||
return this;
|
||||
|
|
Loading…
Add table
Reference in a new issue