From 362ecf640bf449334ccda8361776045e08e8860f Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Fri, 26 Sep 2008 09:04:02 +0000 Subject: [PATCH] Fixed a bug where DiscardClient didn't work since the last optimization --- .../netty/channel/socket/nio/NioWorker.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/jboss/netty/channel/socket/nio/NioWorker.java b/src/main/java/org/jboss/netty/channel/socket/nio/NioWorker.java index e42830a267..395e191326 100644 --- a/src/main/java/org/jboss/netty/channel/socket/nio/NioWorker.java +++ b/src/main/java/org/jboss/netty/channel/socket/nio/NioWorker.java @@ -318,14 +318,17 @@ class NioWorker implements Runnable { static void write(final NioSocketChannel channel, boolean mightNeedWakeup) { if (mightNeedWakeup) { NioWorker worker = channel.getWorker(); - if (worker != null && Thread.currentThread() != worker.thread) { - if (channel.writeTaskInTaskQueue.compareAndSet(false, true)) { - worker.taskQueue.offer(channel.writeTask); + if (worker != null) { + Thread workerThread = worker.thread; + if (workerThread != null && Thread.currentThread() != workerThread) { + if (channel.writeTaskInTaskQueue.compareAndSet(false, true)) { + worker.taskQueue.offer(channel.writeTask); + } + if (worker.wakenUp.compareAndSet(false, true)) { + worker.selector.wakeup(); + } + return; } - if (worker.wakenUp.compareAndSet(false, true)) { - worker.selector.wakeup(); - } - return; } } @@ -367,7 +370,6 @@ class NioWorker implements Runnable { if (internalWriteBuffer.isEmpty()) { channel.writeBuffer.drainTo(internalWriteBuffer); } - evt = channel.currentWriteEvent; for (;;) { if (evt == null) {