Ported the dead lock detector in DefaultChannelFuture to DefaultChannelGroupFuture.

This commit is contained in:
Trustin Lee 2009-04-23 06:55:45 +00:00
parent 563fd2c286
commit c4ba12e8d4

View File

@ -38,6 +38,7 @@ import org.jboss.netty.channel.ChannelFuture;
import org.jboss.netty.channel.ChannelFutureListener;
import org.jboss.netty.logging.InternalLogger;
import org.jboss.netty.logging.InternalLoggerFactory;
import org.jboss.netty.util.internal.IoWorkerRunnable;
/**
* The default {@link ChannelGroupFuture} implementation.
@ -210,6 +211,7 @@ public class DefaultChannelGroupFuture implements ChannelGroupFuture {
public ChannelGroupFuture await() throws InterruptedException {
synchronized (this) {
while (!done) {
checkDeadLock();
waiters++;
try {
this.wait();
@ -233,6 +235,7 @@ public class DefaultChannelGroupFuture implements ChannelGroupFuture {
public ChannelGroupFuture awaitUninterruptibly() {
synchronized (this) {
while (!done) {
checkDeadLock();
waiters++;
try {
this.wait();
@ -274,6 +277,7 @@ public class DefaultChannelGroupFuture implements ChannelGroupFuture {
return done;
}
checkDeadLock();
waiters++;
try {
for (;;) {
@ -300,6 +304,14 @@ public class DefaultChannelGroupFuture implements ChannelGroupFuture {
}
}
private void checkDeadLock() {
if (IoWorkerRunnable.IN_IO_THREAD.get()) {
throw new IllegalStateException(
"await*() in I/O thread causes a dead lock or " +
"sudden performance drop.");
}
}
boolean setDone() {
synchronized (this) {
// Allow only once.