Revert "DefaultPromise make listeners not volatile"
This reverts commit 4d8132ff24
as I missed something I want to discuss first.
This commit is contained in:
parent
4d8132ff24
commit
6492cb98b2
@ -27,7 +27,6 @@ import io.netty.channel.DefaultChannelPromise;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
import io.netty.util.concurrent.EventExecutor;
|
||||
import io.netty.util.concurrent.GenericFutureListener;
|
||||
import io.netty.util.concurrent.ImmediateEventExecutor;
|
||||
import io.netty.util.concurrent.Promise;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@ -125,7 +124,7 @@ public class Http2ConnectionHandlerTest {
|
||||
public void setup() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
promise = new DefaultChannelPromise(channel, ImmediateEventExecutor.INSTANCE);
|
||||
promise = new DefaultChannelPromise(channel);
|
||||
|
||||
Throwable fakeException = new RuntimeException("Fake exception");
|
||||
when(encoder.connection()).thenReturn(connection);
|
||||
|
@ -60,7 +60,7 @@ public class DefaultPromise<V> extends AbstractFuture<V> implements Promise<V> {
|
||||
*
|
||||
* Threading - synchronized(this). We must support adding listeners when there is no EventExecutor.
|
||||
*/
|
||||
private Object listeners;
|
||||
private volatile Object listeners;
|
||||
/**
|
||||
* Threading - synchronized(this). We are required to hold the monitor to use Java's underlying wait()/notifyAll().
|
||||
*/
|
||||
@ -417,6 +417,13 @@ public class DefaultPromise<V> extends AbstractFuture<V> implements Promise<V> {
|
||||
}
|
||||
|
||||
private void notifyListeners() {
|
||||
if (listeners == null) {
|
||||
return;
|
||||
}
|
||||
notifyListenersWithStackOverFlowProtection();
|
||||
}
|
||||
|
||||
private void notifyListenersWithStackOverFlowProtection() {
|
||||
EventExecutor executor = executor();
|
||||
if (executor.inEventLoop()) {
|
||||
final InternalThreadLocalMap threadLocals = InternalThreadLocalMap.get();
|
||||
@ -441,7 +448,7 @@ public class DefaultPromise<V> extends AbstractFuture<V> implements Promise<V> {
|
||||
}
|
||||
|
||||
/**
|
||||
* The logic in this method should be identical to {@link #notifyListeners()} but
|
||||
* The logic in this method should be identical to {@link #notifyListenersWithStackOverFlowProtection()} but
|
||||
* cannot share code because the listener(s) cannot be cached for an instance of {@link DefaultPromise} since the
|
||||
* listener(s) may be changed and is protected by a synchronized operation.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user