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 @Override
public synchronized boolean isWritable(ReadyListener callback) { public boolean isWritable(ReadyListener callback) {
if (!ready) { synchronized (readyListeners) {
readyListeners.push(callback); if (!ready) {
} readyListeners.push(callback);
}
return ready; return ready;
}
} }
@Override @Override
public synchronized void fireReady(final boolean ready) { public void fireReady(final boolean ready) {
this.ready = ready; LinkedList<ReadyListener> readyToCall = null;
synchronized (readyListeners) {
this.ready = ready;
if (ready) { if (ready) {
for (;;) { for (;;) {
ReadyListener readyListener = readyListeners.poll(); ReadyListener readyListener = readyListeners.poll();
if (readyListener == null) { if (readyListener == null) {
return; break;
}
if (readyToCall == null) {
readyToCall = new LinkedList<>();
}
readyToCall.add(readyListener);
} }
}
}
if (readyToCall != null) {
for (ReadyListener readyListener : readyToCall) {
try { try {
readyListener.readyForWriting(); readyListener.readyForWriting();
} }