21
21
import rx .Subscription ;
22
22
import rx .exceptions .MissingBackpressureException ;
23
23
import rx .internal .operators .NotificationLite ;
24
+ import rx .internal .util .unsafe .SpmcArrayQueue ;
25
+ import rx .internal .util .unsafe .SpscArrayQueue ;
24
26
import rx .internal .util .unsafe .UnsafeAccess ;
25
27
26
28
/**
@@ -31,28 +33,16 @@ public class RxRingBuffer implements Subscription {
31
33
32
34
public static RxRingBuffer getSpscInstance () {
33
35
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 );
41
38
} else {
42
39
return new RxRingBuffer ();
43
40
}
44
41
}
45
42
46
43
public static RxRingBuffer getSpmcInstance () {
47
44
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 );
56
46
} else {
57
47
return new RxRingBuffer ();
58
48
}
@@ -170,6 +160,24 @@ public static RxRingBuffer getSpmcInstance() {
170
160
171
161
public static final int SIZE = 1024 ;
172
162
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
+
173
181
private RxRingBuffer (Queue <Object > queue , int size ) {
174
182
this .queue = queue ;
175
183
this .pool = null ;
0 commit comments