2121import rx .Subscription ;
2222import rx .exceptions .MissingBackpressureException ;
2323import rx .internal .operators .NotificationLite ;
24+ import rx .internal .util .unsafe .SpmcArrayQueue ;
25+ import rx .internal .util .unsafe .SpscArrayQueue ;
2426import rx .internal .util .unsafe .UnsafeAccess ;
2527
2628/**
@@ -31,28 +33,16 @@ public class RxRingBuffer implements Subscription {
3133
3234 public static RxRingBuffer getSpscInstance () {
3335 if (UnsafeAccess .isUnsafeAvailable ()) {
34- // using SynchronizedQueue until issues are solved with SpscArrayQueue offer rejection
35- // RxRingBufferSpmcTest.testConcurrency occasionally fails with a
36- // BackpressureException when using SpscArrayQueue
37- // return new RxRingBuffer(SPSC_POOL, SIZE); // this is the one we were trying to use
38- // return new RxRingBuffer(new SpscArrayQueue<Object>(SIZE), SIZE);
39- // the performance of this is sufficient (actually faster in some cases)
40- return new RxRingBuffer (new SynchronizedQueue <Object >(SIZE ), SIZE );
36+ // TODO the SpscArrayQueue isn't ready yet so using SpmcArrayQueue for now
37+ return new RxRingBuffer (SPMC_POOL , SIZE );
4138 } else {
4239 return new RxRingBuffer ();
4340 }
4441 }
4542
4643 public static RxRingBuffer getSpmcInstance () {
4744 if (UnsafeAccess .isUnsafeAvailable ()) {
48- // using SynchronizedQueue until issues are solved with SpmcArrayQueue offer rejection
49- // RxRingBufferSpmcTest.testConcurrency occasionally fails with a
50- // BackpressureException when using SpmcArrayQueue/MpmcArrayQueue
51- // return new RxRingBuffer(SPMC_POOL, SIZE); // this is the one we were trying to use
52- // return new RxRingBuffer(new SpmcArrayQueue<Object>(SIZE), SIZE);
53- // return new RxRingBuffer(new MpmcArrayQueue<Object>(SIZE), SIZE);
54- // the performance of this is sufficient (actually faster in some cases)
55- return new RxRingBuffer (new SynchronizedQueue <Object >(SIZE ), SIZE );
45+ return new RxRingBuffer (SPMC_POOL , SIZE );
5646 } else {
5747 return new RxRingBuffer ();
5848 }
@@ -170,6 +160,24 @@ public static RxRingBuffer getSpmcInstance() {
170160
171161 public static final int SIZE = 1024 ;
172162
163+ private static ObjectPool <Queue <Object >> SPSC_POOL = new ObjectPool <Queue <Object >>() {
164+
165+ @ Override
166+ protected SpscArrayQueue <Object > createObject () {
167+ return new SpscArrayQueue <Object >(SIZE );
168+ }
169+
170+ };
171+
172+ private static ObjectPool <Queue <Object >> SPMC_POOL = new ObjectPool <Queue <Object >>() {
173+
174+ @ Override
175+ protected SpmcArrayQueue <Object > createObject () {
176+ return new SpmcArrayQueue <Object >(SIZE );
177+ }
178+
179+ };
180+
173181 private RxRingBuffer (Queue <Object > queue , int size ) {
174182 this .queue = queue ;
175183 this .pool = null ;
0 commit comments