@@ -194,7 +194,7 @@ private void handleNewSource(Observable<? extends T> t) {
194
194
}
195
195
MergeProducer <T > producerIfNeeded = null ;
196
196
// if we have received a request then we need to respect it, otherwise we fast-path
197
- if (mergeProducer .requested != Long .MAX_VALUE ) {
197
+ if (mergeProducer .requested () != Long .MAX_VALUE ) {
198
198
/**
199
199
* <pre> {@code
200
200
* With this optimization:
@@ -237,7 +237,7 @@ private void handleScalarSynchronousObservable(ScalarSynchronousObservable<? ext
237
237
* } </pre>
238
238
*
239
239
*/
240
- if (mergeProducer .requested == Long .MAX_VALUE ) {
240
+ if (mergeProducer .requested () == Long .MAX_VALUE ) {
241
241
handleScalarSynchronousObservableWithoutRequestLimits (t );
242
242
} else {
243
243
handleScalarSynchronousObservableWithRequestLimits (t );
@@ -274,11 +274,11 @@ private void handleScalarSynchronousObservableWithRequestLimits(ScalarSynchronou
274
274
boolean moreToDrain ;
275
275
boolean isReturn = false ;
276
276
try {
277
- long r = mergeProducer .requested ;
277
+ long r = mergeProducer .requested () ;
278
278
if (r > 0 ) {
279
279
emitted = true ;
280
280
actual .onNext (t .get ());
281
- MergeProducer . REQUESTED . decrementAndGet ( mergeProducer );
281
+ mergeProducer . getAndAdd (- 1 );
282
282
// we handle this Observable without ever incrementing the wip or touching other machinery so just return here
283
283
isReturn = true ;
284
284
}
@@ -376,7 +376,7 @@ private void drainChildrenQueues() {
376
376
private int drainScalarValueQueue () {
377
377
RxRingBuffer svq = scalarValueQueue ;
378
378
if (svq != null ) {
379
- long r = mergeProducer .requested ;
379
+ long r = mergeProducer .requested () ;
380
380
int emittedWhileDraining = 0 ;
381
381
if (r < 0 ) {
382
382
// drain it all
@@ -398,7 +398,7 @@ private int drainScalarValueQueue() {
398
398
}
399
399
}
400
400
// decrement the number we emitted from outstanding requests
401
- MergeProducer . REQUESTED . getAndAdd (mergeProducer , -emittedWhileDraining );
401
+ mergeProducer . getAndAdd (-emittedWhileDraining );
402
402
}
403
403
return emittedWhileDraining ;
404
404
}
@@ -410,7 +410,7 @@ private int drainScalarValueQueue() {
410
410
@ Override
411
411
public Boolean call (InnerSubscriber <T > s ) {
412
412
if (s .q != null ) {
413
- long r = mergeProducer .requested ;
413
+ long r = mergeProducer .requested () ;
414
414
int emitted = s .drainQueue ();
415
415
if (emitted > 0 ) {
416
416
s .requestMore (emitted );
@@ -533,19 +533,26 @@ public MergeProducer(MergeSubscriber<T> ms) {
533
533
this .ms = ms ;
534
534
}
535
535
536
- private volatile long requested = 0 ;
536
+ private volatile long rq = 0 ;
537
537
@ SuppressWarnings ("rawtypes" )
538
- static final AtomicLongFieldUpdater <MergeProducer > REQUESTED = AtomicLongFieldUpdater .newUpdater (MergeProducer .class , "requested " );
538
+ static final AtomicLongFieldUpdater <MergeProducer > RQ = AtomicLongFieldUpdater .newUpdater (MergeProducer .class , "rq " );
539
539
540
+ public long requested () {
541
+ return rq ;
542
+ }
543
+ public long getAndAdd (long n ) {
544
+ return RQ .getAndAdd (this , n );
545
+ }
546
+
540
547
@ Override
541
548
public void request (long n ) {
542
- if (requested == Long .MAX_VALUE ) {
549
+ if (rq == Long .MAX_VALUE ) {
543
550
return ;
544
551
}
545
552
if (n == Long .MAX_VALUE ) {
546
- requested = Long .MAX_VALUE ;
553
+ rq = Long .MAX_VALUE ;
547
554
} else {
548
- BackpressureUtils .getAndAddRequest (REQUESTED , this , n );
555
+ BackpressureUtils .getAndAddRequest (RQ , this , n );
549
556
if (ms .drainQueuesIfNeeded ()) {
550
557
boolean sendComplete = false ;
551
558
synchronized (ms ) {
@@ -668,7 +675,7 @@ private void emit(T t, boolean complete) {
668
675
} else {
669
676
// this needs to check q.count() as draining above may not have drained the full queue
670
677
// perf tests show this to be okay, though different queue implementations could perform poorly with this
671
- if (producer .requested > 0 && q .count () == 0 ) {
678
+ if (producer .requested () > 0 && q .count () == 0 ) {
672
679
if (complete ) {
673
680
parentSubscriber .completeInner (this );
674
681
} else {
@@ -679,7 +686,7 @@ private void emit(T t, boolean complete) {
679
686
onError (OnErrorThrowable .addValueAsLastCause (e , t ));
680
687
}
681
688
emitted ++;
682
- MergeProducer . REQUESTED . decrementAndGet ( producer );
689
+ producer . getAndAdd (- 1 );
683
690
}
684
691
} else {
685
692
// no requests available, so enqueue it
@@ -728,7 +735,7 @@ private void enqueue(T t, boolean complete) {
728
735
private int drainRequested () {
729
736
int emitted = 0 ;
730
737
// drain what was requested
731
- long toEmit = producer .requested ;
738
+ long toEmit = producer .requested () ;
732
739
Object o ;
733
740
for (int i = 0 ; i < toEmit ; i ++) {
734
741
o = q .poll ();
@@ -750,7 +757,7 @@ private int drainRequested() {
750
757
}
751
758
752
759
// decrement the number we emitted from outstanding requests
753
- MergeProducer . REQUESTED . getAndAdd (producer , -emitted );
760
+ producer . getAndAdd (-emitted );
754
761
return emitted ;
755
762
}
756
763
0 commit comments