Skip to content

Commit a85a11e

Browse files
committed
revert visibility of fields and add == this check for guarded subscription
1 parent 3b6707a commit a85a11e

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/main/java/rx/internal/operators/OperatorMulticast.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@
3838
* the result value type
3939
*/
4040
public final class OperatorMulticast<T, R> extends ConnectableObservable<R> {
41-
private final Observable<? extends T> source;
42-
private final Object guard;
43-
private final Func0<? extends Subject<? super T, ? extends R>> subjectFactory;
44-
private final AtomicReference<Subject<? super T, ? extends R>> connectedSubject;
45-
private final List<Subscriber<? super R>> waitingForConnect;
41+
final Observable<? extends T> source;
42+
final Object guard;
43+
final Func0<? extends Subject<? super T, ? extends R>> subjectFactory;
44+
final AtomicReference<Subject<? super T, ? extends R>> connectedSubject;
45+
final List<Subscriber<? super R>> waitingForConnect;
4646

4747
/** Guarded by guard. */
4848
private Subscriber<T> subscription;
@@ -109,21 +109,26 @@ public void onNext(T args) {
109109
subject.onNext(args);
110110
}
111111
};
112-
guardedSubscription = Subscriptions.create(new Action0() {
112+
final AtomicReference<Subscription> gs = new AtomicReference<Subscription>();
113+
gs.set(Subscriptions.create(new Action0() {
113114
@Override
114115
public void call() {
115116
Subscription s;
116117
synchronized (guard) {
117-
s = subscription;
118-
subscription = null;
119-
guardedSubscription = null;
120-
connectedSubject.set(null);
118+
if ( guardedSubscription == gs.get()) {
119+
s = subscription;
120+
subscription = null;
121+
guardedSubscription = null;
122+
connectedSubject.set(null);
123+
} else
124+
return;
121125
}
122126
if (s != null) {
123127
s.unsubscribe();
124128
}
125129
}
126-
});
130+
}));
131+
guardedSubscription = gs.get();
127132

128133
// register any subscribers that are waiting with this new subject
129134
for(Subscriber<? super R> s : waitingForConnect) {

0 commit comments

Comments
 (0)