@@ -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 . getAndAdd (- 1 );
281
+ MergeProducer . REQUESTED . decrementAndGet ( mergeProducer );
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 . getAndAdd (-emittedWhileDraining );
401
+ MergeProducer . REQUESTED . getAndAdd (mergeProducer , -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,26 +533,19 @@ public MergeProducer(MergeSubscriber<T> ms) {
533
533
this .ms = ms ;
534
534
}
535
535
536
- private volatile long rq = 0 ;
536
+ private volatile long requested = 0 ;
537
537
@ SuppressWarnings ("rawtypes" )
538
- static final AtomicLongFieldUpdater <MergeProducer > RQ = AtomicLongFieldUpdater .newUpdater (MergeProducer .class , "rq " );
538
+ static final AtomicLongFieldUpdater <MergeProducer > REQUESTED = AtomicLongFieldUpdater .newUpdater (MergeProducer .class , "requested " );
539
539
540
- public long requested () {
541
- return rq ;
542
- }
543
- public long getAndAdd (long n ) {
544
- return RQ .getAndAdd (this , n );
545
- }
546
-
547
540
@ Override
548
541
public void request (long n ) {
549
- if (rq == Long .MAX_VALUE ) {
542
+ if (requested == Long .MAX_VALUE ) {
550
543
return ;
551
544
}
552
545
if (n == Long .MAX_VALUE ) {
553
- rq = Long .MAX_VALUE ;
546
+ requested = Long .MAX_VALUE ;
554
547
} else {
555
- BackpressureUtils .getAndAddRequest (RQ , this , n );
548
+ BackpressureUtils .getAndAddRequest (REQUESTED , this , n );
556
549
if (ms .drainQueuesIfNeeded ()) {
557
550
boolean sendComplete = false ;
558
551
synchronized (ms ) {
@@ -675,7 +668,7 @@ private void emit(T t, boolean complete) {
675
668
} else {
676
669
// this needs to check q.count() as draining above may not have drained the full queue
677
670
// perf tests show this to be okay, though different queue implementations could perform poorly with this
678
- if (producer .requested () > 0 && q .count () == 0 ) {
671
+ if (producer .requested > 0 && q .count () == 0 ) {
679
672
if (complete ) {
680
673
parentSubscriber .completeInner (this );
681
674
} else {
@@ -686,7 +679,7 @@ private void emit(T t, boolean complete) {
686
679
onError (OnErrorThrowable .addValueAsLastCause (e , t ));
687
680
}
688
681
emitted ++;
689
- producer . getAndAdd (- 1 );
682
+ MergeProducer . REQUESTED . decrementAndGet ( producer );
690
683
}
691
684
} else {
692
685
// no requests available, so enqueue it
@@ -735,7 +728,7 @@ private void enqueue(T t, boolean complete) {
735
728
private int drainRequested () {
736
729
int emitted = 0 ;
737
730
// drain what was requested
738
- long toEmit = producer .requested () ;
731
+ long toEmit = producer .requested ;
739
732
Object o ;
740
733
for (int i = 0 ; i < toEmit ; i ++) {
741
734
o = q .poll ();
@@ -757,7 +750,7 @@ private int drainRequested() {
757
750
}
758
751
759
752
// decrement the number we emitted from outstanding requests
760
- producer . getAndAdd (-emitted );
753
+ MergeProducer . REQUESTED . getAndAdd (producer , -emitted );
761
754
return emitted ;
762
755
}
763
756
0 commit comments