[jboss-remoting-commits] JBoss Remoting SVN: r3582 - remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util.
jboss-remoting-commits at lists.jboss.org
jboss-remoting-commits at lists.jboss.org
Thu Mar 6 23:17:27 EST 2008
Author: david.lloyd at jboss.com
Date: 2008-03-06 23:17:27 -0500 (Thu, 06 Mar 2008)
New Revision: 3582
Modified:
remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/AtomicStateMachine.java
Log:
Add read lock protected test to start of wait methods
Modified: remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/AtomicStateMachine.java
===================================================================
--- remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/AtomicStateMachine.java 2008-03-07 04:15:30 UTC (rev 3581)
+++ remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/AtomicStateMachine.java 2008-03-07 04:17:27 UTC (rev 3582)
@@ -208,6 +208,9 @@
public void waitInterruptiblyFor(final T state) throws InterruptedException {
+ if (in(state)) {
+ return;
+ }
writeLock.lockInterruptibly();
try {
while (this.state != state) {
@@ -219,6 +222,9 @@
}
public void waitFor(final T state) {
+ if (in(state)) {
+ return;
+ }
writeLock.lock();
try {
while (this.state != state) {
@@ -230,6 +236,9 @@
}
public void waitForHold(final T state) {
+ if (inHold(state)) {
+ return;
+ }
writeLock.lock();
try {
while (this.state != state) {
@@ -251,6 +260,9 @@
}
public boolean waitInterruptiblyFor(final T state, final long timeout, final TimeUnit timeUnit) throws InterruptedException {
+ if (in(state)) {
+ return true;
+ }
final long timeoutMillis = timeUnit.toMillis(timeout);
final long startTime = System.currentTimeMillis();
final long endTime = startTime + timeoutMillis < 0 ? Long.MAX_VALUE : startTime + timeoutMillis;
@@ -269,6 +281,10 @@
}
public T waitInterruptiblyForNot(final T state) throws InterruptedException {
+ final T current = getState();
+ if (current != state) {
+ return current;
+ }
writeLock.lockInterruptibly();
try {
while (this.state == state) {
@@ -281,6 +297,11 @@
}
public T waitInterruptiblyForNotHold(final T state) throws InterruptedException {
+ final T current = getStateHold();
+ if (current != state) {
+ return current;
+ }
+ release();
writeLock.lockInterruptibly();
try {
while (this.state == state) {
@@ -294,6 +315,10 @@
}
public T waitForNot(final T state) {
+ final T current = getState();
+ if (current != state) {
+ return current;
+ }
writeLock.lock();
try {
while (this.state == state) {
@@ -306,6 +331,11 @@
}
public T waitForNotHold(final T state) {
+ final T current = getStateHold();
+ if (current != state) {
+ return current;
+ }
+ release();
writeLock.lock();
try {
while (this.state == state) {
@@ -327,6 +357,10 @@
}
public T waitInterruptiblyForNot(final T state, final long timeout, final TimeUnit timeUnit) throws InterruptedException {
+ final T current = getState();
+ if (current != state) {
+ return current;
+ }
final long timeoutMillis = timeUnit.toMillis(timeout);
final long startTime = System.currentTimeMillis();
final long endTime = startTime + timeoutMillis < 0 ? Long.MAX_VALUE : startTime + timeoutMillis;
@@ -344,6 +378,11 @@
public T waitInterruptiblyForNotHold(final T state, final long timeout, final TimeUnit timeUnit) throws InterruptedException {
+ final T current = getStateHold();
+ if (current != state) {
+ return current;
+ }
+ release();
final long timeoutMillis = timeUnit.toMillis(timeout);
final long startTime = System.currentTimeMillis();
final long endTime = startTime + timeoutMillis < 0 ? Long.MAX_VALUE : startTime + timeoutMillis;
@@ -366,6 +405,11 @@
}
public T waitForNotHold(final T state, final long timeout, final TimeUnit timeUnit) {
+ final T current = getStateHold();
+ if (current != state) {
+ return current;
+ }
+ release();
final long timeoutMillis = timeUnit.toMillis(timeout);
final long startTime = System.currentTimeMillis();
final long endTime = startTime + timeoutMillis < 0 ? Long.MAX_VALUE : startTime + timeoutMillis;
@@ -397,6 +441,10 @@
}
public T waitForNot(final T state, final long timeout, final TimeUnit timeUnit) {
+ final T current = getState();
+ if (current != state) {
+ return current;
+ }
final long timeoutMillis = timeUnit.toMillis(timeout);
final long startTime = System.currentTimeMillis();
final long endTime = startTime + timeoutMillis < 0 ? Long.MAX_VALUE : startTime + timeoutMillis;
More information about the jboss-remoting-commits
mailing list