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.channel.ChannelFutureListener;
import org.jboss.netty.logging.InternalLogger; import org.jboss.netty.logging.InternalLogger;
import org.jboss.netty.logging.InternalLoggerFactory; import org.jboss.netty.logging.InternalLoggerFactory;
import org.jboss.netty.util.internal.IoWorkerRunnable;
/** /**
* The default {@link ChannelGroupFuture} implementation. * The default {@link ChannelGroupFuture} implementation.
@ -210,6 +211,7 @@ public class DefaultChannelGroupFuture implements ChannelGroupFuture {
public ChannelGroupFuture await() throws InterruptedException { public ChannelGroupFuture await() throws InterruptedException {
synchronized (this) { synchronized (this) {
while (!done) { while (!done) {
checkDeadLock();
waiters++; waiters++;
try { try {
this.wait(); this.wait();
@ -233,6 +235,7 @@ public class DefaultChannelGroupFuture implements ChannelGroupFuture {
public ChannelGroupFuture awaitUninterruptibly() { public ChannelGroupFuture awaitUninterruptibly() {
synchronized (this) { synchronized (this) {
while (!done) { while (!done) {
checkDeadLock();
waiters++; waiters++;
try { try {
this.wait(); this.wait();
@ -274,6 +277,7 @@ public class DefaultChannelGroupFuture implements ChannelGroupFuture {
return done; return done;
} }
checkDeadLock();
waiters++; waiters++;
try { try {
for (;;) { 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() { boolean setDone() {
synchronized (this) { synchronized (this) {
// Allow only once. // Allow only once.