@@ -320,12 +320,12 @@ private boolean isSelected() {
320
320
if (chosen ) {
321
321
return true ;
322
322
}
323
- if (selection .choice . get () == this ) {
323
+ if (selection .get () == this ) {
324
324
// fast-path
325
325
chosen = true ;
326
326
return true ;
327
327
} else {
328
- if (selection .choice . compareAndSet (null , this )) {
328
+ if (selection .compareAndSet (null , this )) {
329
329
selection .unsubscribeOthers (this );
330
330
chosen = true ;
331
331
return true ;
@@ -338,12 +338,12 @@ private boolean isSelected() {
338
338
}
339
339
}
340
340
341
- static final class Selection < T > {
342
- final AtomicReference < AmbSubscriber < T >> choice = new AtomicReference <AmbSubscriber <T >>();
341
+ @ SuppressWarnings ( "serial" )
342
+ static final class Selection < T > extends AtomicReference <AmbSubscriber <T >> {
343
343
final Collection <AmbSubscriber <T >> ambSubscribers = new ConcurrentLinkedQueue <AmbSubscriber <T >>();
344
344
345
345
public void unsubscribeLosers () {
346
- AmbSubscriber <T > winner = choice . get ();
346
+ AmbSubscriber <T > winner = get ();
347
347
if (winner != null ) {
348
348
unsubscribeOthers (winner );
349
349
}
@@ -367,15 +367,14 @@ private OnSubscribeAmb(Iterable<? extends Observable<? extends T>> sources) {
367
367
@ Override
368
368
public void call (final Subscriber <? super T > subscriber ) {
369
369
final Selection <T > selection = new Selection <T >();
370
- final AtomicReference <AmbSubscriber <T >> choice = selection .choice ;
371
370
372
371
//setup unsubscription of all the subscribers to the sources
373
372
subscriber .add (Subscriptions .create (new Action0 () {
374
373
375
374
@ Override
376
375
public void call () {
377
376
AmbSubscriber <T > c ;
378
- if ((c = choice .get ()) != null ) {
377
+ if ((c = selection .get ()) != null ) {
379
378
// there is a single winner so we unsubscribe it
380
379
c .unsubscribe ();
381
380
}
@@ -399,7 +398,7 @@ public void call() {
399
398
// if all sources were backpressure aware then this check
400
399
// would be pointless given that 0 was requested above from each ambSubscriber
401
400
AmbSubscriber <T > c ;
402
- if ((c = choice .get ()) != null ) {
401
+ if ((c = selection .get ()) != null ) {
403
402
// Already chose one, the rest can be skipped and we can clean up
404
403
selection .unsubscribeOthers (c );
405
404
return ;
@@ -416,7 +415,7 @@ public void call() {
416
415
@ Override
417
416
public void request (long n ) {
418
417
AmbSubscriber <T > c ;
419
- if ((c = choice .get ()) != null ) {
418
+ if ((c = selection .get ()) != null ) {
420
419
// propagate the request to that single Subscriber that won
421
420
c .requestMore (n );
422
421
} else {
@@ -425,7 +424,7 @@ public void request(long n) {
425
424
if (!ambSubscriber .isUnsubscribed ()) {
426
425
// make a best endeavours check to not waste requests
427
426
// if first emission has already occurred
428
- if (choice .get () == ambSubscriber ) {
427
+ if (selection .get () == ambSubscriber ) {
429
428
ambSubscriber .requestMore (n );
430
429
// don't need to request from other subscribers because choice has been made
431
430
// and request has gone to choice
0 commit comments