ARTEMIS-474 Avoiding one lock around the readyListener call tree and fixing ReplicationManager / NettyConnection deadlock

This commit is contained in:
Clebert Suconic 2016-04-06 12:58:50 -04:00
parent 2e894554ca
commit 3ecd8b7c44
1 changed files with 28 additions and 12 deletions

View File

@ -106,25 +106,41 @@ public class NettyConnection implements Connection {
}
@Override
public synchronized boolean isWritable(ReadyListener callback) {
public boolean isWritable(ReadyListener callback) {
synchronized (readyListeners) {
if (!ready) {
readyListeners.push(callback);
}
return ready;
}
}
@Override
public synchronized void fireReady(final boolean ready) {
public void fireReady(final boolean ready) {
LinkedList<ReadyListener> readyToCall = null;
synchronized (readyListeners) {
this.ready = ready;
if (ready) {
for (;;) {
ReadyListener readyListener = readyListeners.poll();
if (readyListener == null) {
return;
break;
}
if (readyToCall == null) {
readyToCall = new LinkedList<>();
}
readyToCall.add(readyListener);
}
}
}
if (readyToCall != null) {
for (ReadyListener readyListener : readyToCall) {
try {
readyListener.readyForWriting();
}