Skip to content

Commit

Permalink
Put sync.unregister() in finally. See #118
Browse files Browse the repository at this point in the history
  • Loading branch information
pron committed Sep 18, 2015
1 parent ed0bb4b commit fefd6d9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,13 @@ public final <T> T receive(long timeout, TimeUnit unit, MessageProcessor<? super
mailbox.lock();

if (it.hasNext()) {
final Object m = it.next();
mailbox.unlock();
final Object m;

try {
m = it.next();
} finally {
mailbox.unlock();
}
if (m == currentMessage) {
it.remove();
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,17 @@ public Message receive() throws SuspendExecution, InterruptedException {
maybeSetCurrentStrandAsOwner();
Message m;
Object token = sync.register();
for (int i = 0; (m = queue().poll()) == null; i++) {
if (isSendClosed()) {
setReceiveClosed();
checkClosed();
try {
for (int i = 0; (m = queue().poll()) == null; i++) {
if (isSendClosed()) {
setReceiveClosed();
checkClosed();
}
sync.await(i);
}
sync.await(i);
} finally {
sync.unregister(token);
}
sync.unregister(token);

signalSenders();
return m;
Expand Down

0 comments on commit fefd6d9

Please sign in to comment.