More changes to Monitor to attempt to catch a bug.
This commit is contained in:
@@ -118,7 +118,7 @@ public static boolean lock(Monitor monitor, long timeout, boolean allowSuspend,
|
|||||||
}//if//
|
}//if//
|
||||||
|
|
||||||
if(threadData.currentLock == monitor) {
|
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.lockCount++;
|
||||||
threadData.stack = new RuntimeException();
|
threadData.stack = new RuntimeException();
|
||||||
|
|
||||||
@@ -143,6 +143,7 @@ public static boolean lock(Monitor monitor, long timeout, boolean allowSuspend,
|
|||||||
|
|
||||||
synchronized(monitor.lock) {
|
synchronized(monitor.lock) {
|
||||||
if(monitor.lockingThreadData == null) {
|
if(monitor.lockingThreadData == null) {
|
||||||
|
System.out.println("MONITOR: Locking lock: " + Integer.toHexString(monitor.lock.hashCode()));
|
||||||
monitor.lockingThreadData = threadData;
|
monitor.lockingThreadData = threadData;
|
||||||
result = true;
|
result = true;
|
||||||
}//if//
|
}//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 we got the lock then proceed, otherwise we couldn't get the lock in 10 minutes of waiting...
|
||||||
if(monitor.lockingThreadData == null) {
|
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;
|
monitor.lockingThreadData = threadData;
|
||||||
result = true;
|
result = true;
|
||||||
}//if//
|
}//if//
|
||||||
@@ -205,7 +206,7 @@ public static boolean lock(Monitor monitor, long timeout, boolean allowSuspend,
|
|||||||
}//while//
|
}//while//
|
||||||
|
|
||||||
if(monitor.lockingThreadData == null) {
|
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;
|
monitor.lockingThreadData = threadData;
|
||||||
result = true;
|
result = true;
|
||||||
}//if//
|
}//if//
|
||||||
@@ -277,17 +278,16 @@ public static void unlock(Monitor monitor) {
|
|||||||
synchronized(monitor.lock) {
|
synchronized(monitor.lock) {
|
||||||
monitor.lockingThreadData = null;
|
monitor.lockingThreadData = null;
|
||||||
monitor.lock.notify();
|
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//
|
}//synchronized//
|
||||||
|
|
||||||
threadData.currentLock = null;
|
|
||||||
threadData.lockCount = 0;
|
|
||||||
threadData.stack = null;
|
|
||||||
|
|
||||||
resume(threadData);
|
resume(threadData);
|
||||||
}//if//
|
}//if//
|
||||||
else {
|
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//
|
}//else//
|
||||||
//}//if//
|
//}//if//
|
||||||
}//unlock()//
|
}//unlock()//
|
||||||
@@ -313,14 +313,13 @@ private static void suspend(ThreadData threadData) {
|
|||||||
if(threadData.currentLock != null) {
|
if(threadData.currentLock != null) {
|
||||||
//Allow another thread to lock the previously held monitor.//
|
//Allow another thread to lock the previously held monitor.//
|
||||||
synchronized(threadData.currentLock.lock) {
|
synchronized(threadData.currentLock.lock) {
|
||||||
Debug.log("MONITOR: Suspended lock: " + Integer.toHexString(threadData.currentLock.lock.hashCode()));
|
|
||||||
threadData.currentLock.lockingThreadData = null;
|
threadData.currentLock.lockingThreadData = null;
|
||||||
|
threadData.lockCount = 0;
|
||||||
|
threadData.currentLock = null;
|
||||||
|
threadData.stack = null;
|
||||||
threadData.currentLock.lock.notify();
|
threadData.currentLock.lock.notify();
|
||||||
|
System.out.println("MONITOR: Suspended lock: " + Integer.toHexString(threadData.currentLock.lock.hashCode()));
|
||||||
}//synchronized//
|
}//synchronized//
|
||||||
|
|
||||||
threadData.lockCount = 0;
|
|
||||||
threadData.currentLock = null;
|
|
||||||
threadData.stack = null;
|
|
||||||
}//if//
|
}//if//
|
||||||
}//if//
|
}//if//
|
||||||
else {
|
else {
|
||||||
@@ -359,7 +358,7 @@ private static void resume(ThreadData threadData) {
|
|||||||
//Wait until we can lock on the restored monitor.//
|
//Wait until we can lock on the restored monitor.//
|
||||||
synchronized(threadData.currentLock.lock) {
|
synchronized(threadData.currentLock.lock) {
|
||||||
if(threadData.currentLock.lockingThreadData == null) {
|
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;
|
threadData.currentLock.lockingThreadData = threadData;
|
||||||
}//if//
|
}//if//
|
||||||
else {
|
else {
|
||||||
@@ -393,7 +392,7 @@ private static void resume(ThreadData threadData) {
|
|||||||
}//catch//
|
}//catch//
|
||||||
}//while//
|
}//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;
|
threadData.currentLock.lockingThreadData = threadData;
|
||||||
}//else//
|
}//else//
|
||||||
}//synchronized//
|
}//synchronized//
|
||||||
|
|||||||
Reference in New Issue
Block a user