Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the codes out of the finally block #1926

Merged
merged 1 commit into from
Dec 9, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 30 additions & 21 deletions src/main/java/rx/internal/operators/OperatorMerge.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,17 @@ private void handleScalarSynchronousObservable(ScalarSynchronousObservable<? ext
private void handleScalarSynchronousObservableWithoutRequestLimits(ScalarSynchronousObservable<? extends T> t) {
T value = t.get();
if (getEmitLock()) {
boolean moreToDrain;
try {
actual.onNext(value);
return;
} finally {
if (releaseEmitLock()) {
drainQueuesIfNeeded();
}
request(1);
moreToDrain = releaseEmitLock();
}
if (moreToDrain) {
drainQueuesIfNeeded();
}
request(1);
return;
} else {
initScalarValueQueueIfNeeded();
try {
Expand All @@ -241,22 +243,28 @@ private void handleScalarSynchronousObservableWithoutRequestLimits(ScalarSynchro
private void handleScalarSynchronousObservableWithRequestLimits(ScalarSynchronousObservable<? extends T> t) {
if (getEmitLock()) {
boolean emitted = false;
boolean moreToDrain;
boolean isReturn = false;
try {
long r = mergeProducer.requested;
if (r > 0) {
emitted = true;
actual.onNext(t.get());
MergeProducer.REQUESTED.decrementAndGet(mergeProducer);
// we handle this Observable without ever incrementing the wip or touching other machinery so just return here
return;
isReturn = true;
}
} finally {
if (releaseEmitLock()) {
drainQueuesIfNeeded();
}
if (emitted) {
request(1);
}
moreToDrain = releaseEmitLock();
}
if (moreToDrain) {
drainQueuesIfNeeded();
}
if (emitted) {
request(1);
}
if (isReturn) {
return;
}
}

Expand Down Expand Up @@ -301,20 +309,21 @@ private boolean drainQueuesIfNeeded() {
while (true) {
if (getEmitLock()) {
int emitted = 0;
boolean moreToDrain;
try {
emitted = drainScalarValueQueue();
drainChildrenQueues();
} finally {
boolean moreToDrain = releaseEmitLock();
// request outside of lock
if (emitted > 0) {
request(emitted);
}
if (!moreToDrain) {
return true;
}
// otherwise we'll loop and get whatever was added
moreToDrain = releaseEmitLock();
}
// request outside of lock
if (emitted > 0) {
request(emitted);
}
if (!moreToDrain) {
return true;
}
// otherwise we'll loop and get whatever was added
} else {
return false;
}
Expand Down