|
16 | 16 | package rx.internal.operators;
|
17 | 17 |
|
18 | 18 | import java.util.Queue;
|
19 |
| -import java.util.concurrent.atomic.*; |
| 19 | +import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; |
| 20 | +import java.util.concurrent.atomic.AtomicLongFieldUpdater; |
20 | 21 |
|
21 | 22 | import rx.Observable.Operator;
|
22 |
| -import rx.*; |
| 23 | +import rx.Producer; |
| 24 | +import rx.Scheduler; |
| 25 | +import rx.Subscriber; |
| 26 | +import rx.Subscription; |
23 | 27 | import rx.exceptions.MissingBackpressureException;
|
24 | 28 | import rx.functions.Action0;
|
25 |
| -import rx.internal.util.*; |
26 |
| -import rx.internal.util.unsafe.*; |
27 |
| -import rx.schedulers.*; |
| 29 | +import rx.internal.util.RxRingBuffer; |
| 30 | +import rx.internal.util.SynchronizedQueue; |
| 31 | +import rx.internal.util.unsafe.SpscArrayQueue; |
| 32 | +import rx.internal.util.unsafe.UnsafeAccess; |
| 33 | +import rx.schedulers.ImmediateScheduler; |
| 34 | +import rx.schedulers.TrampolineScheduler; |
28 | 35 |
|
29 | 36 | /**
|
30 | 37 | * Delivers events on the specified {@code Scheduler} asynchronously via an unbounded buffer.
|
@@ -54,7 +61,9 @@ public Subscriber<? super T> call(Subscriber<? super T> child) {
|
54 | 61 | // avoid overhead, execute directly
|
55 | 62 | return child;
|
56 | 63 | } else {
|
57 |
| - return new ObserveOnSubscriber<T>(scheduler, child); |
| 64 | + ObserveOnSubscriber<T> parent = new ObserveOnSubscriber<T>(scheduler, child); |
| 65 | + parent.init(); |
| 66 | + return parent; |
58 | 67 | }
|
59 | 68 | }
|
60 | 69 |
|
@@ -91,12 +100,17 @@ public ObserveOnSubscriber(Scheduler scheduler, Subscriber<? super T> child) {
|
91 | 100 | queue = new SynchronizedQueue<Object>(RxRingBuffer.SIZE);
|
92 | 101 | }
|
93 | 102 | this.scheduledUnsubscribe = new ScheduledUnsubscribe(recursiveScheduler);
|
| 103 | + } |
| 104 | + |
| 105 | + void init() { |
| 106 | + // don't want this code in the constructor because `this` can escape through the |
| 107 | + // setProducer call |
94 | 108 | child.add(scheduledUnsubscribe);
|
95 | 109 | child.setProducer(new Producer() {
|
96 | 110 |
|
97 | 111 | @Override
|
98 | 112 | public void request(long n) {
|
99 |
| - REQUESTED.getAndAdd(ObserveOnSubscriber.this, n); |
| 113 | + BackpressureUtils.getAndAddRequest(REQUESTED, ObserveOnSubscriber.this, n); |
100 | 114 | schedule();
|
101 | 115 | }
|
102 | 116 |
|
|
0 commit comments