Skip to content

Commit

Permalink
[netty#1994] DefaultPromise.cancel() should reuse CancellationExcepti…
Browse files Browse the repository at this point in the history
…on for performance reasons
  • Loading branch information
Norman Maurer committed Nov 19, 2013
1 parent d0e928d commit 43943c7
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions common/src/main/java/io/netty/util/concurrent/DefaultPromise.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.netty.util.concurrent;

import io.netty.util.Signal;
import io.netty.util.internal.EmptyArrays;
import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.StringUtil;
import io.netty.util.internal.logging.InternalLogger;
Expand All @@ -39,8 +40,14 @@ protected Integer initialValue() {
return 0;
}
};
private static final Signal SUCCESS = Signal.valueOf(DefaultPromise.class, "SUCCESS");
private static final Signal UNCANCELLABLE = Signal.valueOf(DefaultPromise.class, "UNCANCELLABLE");
private static final Signal SUCCESS = Signal.valueOf(DefaultPromise.class.getName() + ".SUCCESS");
private static final Signal UNCANCELLABLE = Signal.valueOf(DefaultPromise.class.getName() + ".UNCANCELLABLE");
private static final CauseHolder CANCELLATION_CAUSE_HOLDER = new CauseHolder(new CancellationException());

static {
CANCELLATION_CAUSE_HOLDER.cause.setStackTrace(EmptyArrays.EMPTY_STACK_TRACE);
}

private final EventExecutor executor;

private volatile Object result;
Expand Down Expand Up @@ -424,7 +431,7 @@ public boolean cancel(boolean mayInterruptIfRunning) {
return false;
}

this.result = new CauseHolder(new CancellationException());
this.result = CANCELLATION_CAUSE_HOLDER;
if (hasWaiters()) {
notifyAll();
}
Expand Down

0 comments on commit 43943c7

Please sign in to comment.