Author: david.lloyd(a)jboss.com
Date: 2008-03-25 20:12:38 -0400 (Tue, 25 Mar 2008)
New Revision: 3758
Modified:
remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/StateLock.java
Log:
Fix detection of exclusive locking
Modified: remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/StateLock.java
===================================================================
---
remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/StateLock.java 2008-03-25
23:30:48 UTC (rev 3757)
+++
remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/StateLock.java 2008-03-26
00:12:38 UTC (rev 3758)
@@ -43,6 +43,9 @@
// @protectedby {@code lock} (writes only)
private volatile boolean exclusive = false;
+ // @protectedby {@code lock} (all accesses)
+ private int serial = 0;
+
private final ThreadLocal<LockState> localLockState = new
ThreadLocal<LockState>();
private void incLocalExclCount() {
@@ -116,6 +119,7 @@
}
}
exclusive = true;
+ serial++;
incLocalExclCount();
return;
} finally {
@@ -190,14 +194,11 @@
final ReaderToken token = nextReaderToken;
token.count++;
sharedHolderCount--;
- while (! exclusive) {
- try {
- lock.wait();
- } catch (InterruptedException e) {
- intr = true;
- }
+ if (sharedHolderCount == 0) {
+ lock.notifyAll();
}
- while (exclusive) {
+ final int origSerial = serial;
+ while (serial == origSerial || exclusive) {
try {
lock.wait();
} catch (InterruptedException e) {
Show replies by date