More changes to Monitor to attempt to catch a bug.

This commit is contained in:
wcrisman
2014-07-11 16:17:49 -07:00
parent b11dc14fb3
commit 985228d213

View File

@@ -118,7 +118,7 @@ public static boolean lock(Monitor monitor, long timeout, boolean allowSuspend,
}//if//
if(threadData.currentLock == monitor) {
Debug.log("MONITOR: Incrementing lock count: " + Integer.toHexString(monitor.lock.hashCode()));
System.out.println("MONITOR: Incrementing lock count: " + Integer.toHexString(monitor.lock.hashCode()));
threadData.lockCount++;
threadData.stack = new RuntimeException();
@@ -143,6 +143,7 @@ public static boolean lock(Monitor monitor, long timeout, boolean allowSuspend,
synchronized(monitor.lock) {
if(monitor.lockingThreadData == null) {
System.out.println("MONITOR: Locking lock: " + Integer.toHexString(monitor.lock.hashCode()));
monitor.lockingThreadData = threadData;
result = true;
}//if//
@@ -184,7 +185,7 @@ public static boolean lock(Monitor monitor, long timeout, boolean allowSuspend,
//If we got the lock then proceed, otherwise we couldn't get the lock in 10 minutes of waiting...
if(monitor.lockingThreadData == null) {
Debug.log("MONITOR: Locking lock: " + Integer.toHexString(monitor.lock.hashCode()));
System.out.println("MONITOR: Locking lock: " + Integer.toHexString(monitor.lock.hashCode()));
monitor.lockingThreadData = threadData;
result = true;
}//if//
@@ -205,7 +206,7 @@ public static boolean lock(Monitor monitor, long timeout, boolean allowSuspend,
}//while//
if(monitor.lockingThreadData == null) {
Debug.log("MONITOR: Locking lock: " + Integer.toHexString(monitor.lock.hashCode()));
System.out.println("MONITOR: Locking lock: " + Integer.toHexString(monitor.lock.hashCode()));
monitor.lockingThreadData = threadData;
result = true;
}//if//
@@ -277,17 +278,16 @@ public static void unlock(Monitor monitor) {
synchronized(monitor.lock) {
monitor.lockingThreadData = null;
monitor.lock.notify();
Debug.log("MONITOR: Unlocking lock: " + Integer.toHexString(monitor.lock.hashCode()));
threadData.currentLock = null;
threadData.lockCount = 0;
threadData.stack = null;
System.out.println("MONITOR: Unlocking lock: " + Integer.toHexString(monitor.lock.hashCode()));
}//synchronized//
threadData.currentLock = null;
threadData.lockCount = 0;
threadData.stack = null;
resume(threadData);
}//if//
else {
Debug.log("MONITOR: Decremented lock count: " + Integer.toHexString(monitor.lock.hashCode()));
System.out.println("MONITOR: Decremented lock count: " + Integer.toHexString(monitor.lock.hashCode()));
}//else//
//}//if//
}//unlock()//
@@ -313,14 +313,13 @@ private static void suspend(ThreadData threadData) {
if(threadData.currentLock != null) {
//Allow another thread to lock the previously held monitor.//
synchronized(threadData.currentLock.lock) {
Debug.log("MONITOR: Suspended lock: " + Integer.toHexString(threadData.currentLock.lock.hashCode()));
threadData.currentLock.lockingThreadData = null;
threadData.lockCount = 0;
threadData.currentLock = null;
threadData.stack = null;
threadData.currentLock.lock.notify();
System.out.println("MONITOR: Suspended lock: " + Integer.toHexString(threadData.currentLock.lock.hashCode()));
}//synchronized//
threadData.lockCount = 0;
threadData.currentLock = null;
threadData.stack = null;
}//if//
}//if//
else {
@@ -359,7 +358,7 @@ private static void resume(ThreadData threadData) {
//Wait until we can lock on the restored monitor.//
synchronized(threadData.currentLock.lock) {
if(threadData.currentLock.lockingThreadData == null) {
Debug.log("MONITOR: Resuming lock (no wait): " + Integer.toHexString(threadData.currentLock.lock.hashCode()));
System.out.println("MONITOR: Resuming lock (no wait): " + Integer.toHexString(threadData.currentLock.lock.hashCode()));
threadData.currentLock.lockingThreadData = threadData;
}//if//
else {
@@ -393,7 +392,7 @@ private static void resume(ThreadData threadData) {
}//catch//
}//while//
Debug.log("MONITOR: Resuming lock (after wait): " + Integer.toHexString(threadData.currentLock.lock.hashCode()));
System.out.println("MONITOR: Resuming lock (after wait): " + Integer.toHexString(threadData.currentLock.lock.hashCode()));
threadData.currentLock.lockingThreadData = threadData;
}//else//
}//synchronized//