From c4ba12e8d44a23c9456a3abcefa396a44b80553a Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Thu, 23 Apr 2009 06:55:45 +0000 Subject: [PATCH] Ported the dead lock detector in DefaultChannelFuture to DefaultChannelGroupFuture. --- .../channel/group/DefaultChannelGroupFuture.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/org/jboss/netty/channel/group/DefaultChannelGroupFuture.java b/src/main/java/org/jboss/netty/channel/group/DefaultChannelGroupFuture.java index 659f26de32..fc4ffd86b0 100644 --- a/src/main/java/org/jboss/netty/channel/group/DefaultChannelGroupFuture.java +++ b/src/main/java/org/jboss/netty/channel/group/DefaultChannelGroupFuture.java @@ -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.