File tree Expand file tree Collapse file tree 1 file changed +21
-13
lines changed
src/main/java/rx/internal/operators Expand file tree Collapse file tree 1 file changed +21
-13
lines changed Original file line number Diff line number Diff line change @@ -236,21 +236,29 @@ public void onError(Throwable e) {
236
236
@ Override
237
237
public void onNext (T v ) {
238
238
if (!done ) {
239
- child .onNext (v );
240
- while (true ) {
241
- long cc = consumerCapacity .get ();
242
- if (cc == 0 ) {
243
- child .onError (new MissingBackpressureException (
244
- "an item has arrived to this operator that was not requested, "
245
- + "please use backpressure aware operators upstream (or append .onBackpressureBuffer() or similar)" ));
246
- break ;
247
- } else if (cc != Long .MAX_VALUE ) {
248
- if (consumerCapacity .compareAndSet (cc , cc - 1 )) {
249
- break ;
250
- }
251
- } else {
239
+ if (consumerCapacity .get () == 0 ) {
240
+ child .onError (new MissingBackpressureException (
241
+ "an item has arrived to this operator that was not requested, "
242
+ + "please use backpressure aware operators upstream (or insert .onBackpressureBuffer() or similar)" ));
243
+ return ;
244
+ } else {
245
+ child .onNext (v );
246
+ decrementConsumerCapacity ();
247
+ }
248
+ }
249
+ }
250
+
251
+ private void decrementConsumerCapacity () {
252
+ // use a CAS loop because we don't want to decrement the value
253
+ // if it is Long.MAX_VALUE
254
+ while (true ) {
255
+ long cc = consumerCapacity .get ();
256
+ if (cc != Long .MAX_VALUE ) {
257
+ if (consumerCapacity .compareAndSet (cc , cc - 1 )) {
252
258
break ;
253
259
}
260
+ } else {
261
+ break ;
254
262
}
255
263
}
256
264
}
You can’t perform that action at this time.
0 commit comments