23
23
#import " RACSubject.h"
24
24
#import " RACSubscriber+Private.h"
25
25
#import " RACTuple.h"
26
- #import < libkern/OSAtomic .h>
26
+ #import < stdatomic .h>
27
27
28
28
@implementation RACSignal
29
29
@@ -108,12 +108,12 @@ - (RACSignal *)bind:(RACSignalBindBlock (^)(void))block {
108
108
return [[RACSignal createSignal: ^(id <RACSubscriber> subscriber) {
109
109
RACSignalBindBlock bindingBlock = block ();
110
110
111
- __block volatile int32_t signalCount = 1 ; // indicates self
111
+ __block atomic_int signalCount = 1 ; // indicates self
112
112
113
113
RACCompoundDisposable *compoundDisposable = [RACCompoundDisposable compoundDisposable ];
114
114
115
115
void (^completeSignal)(RACDisposable *) = ^(RACDisposable *finishedDisposable) {
116
- if (OSAtomicDecrement32Barrier (&signalCount) == 0 ) {
116
+ if (atomic_fetch_sub (&signalCount, 1 ) - 1 == 0 ) {
117
117
[subscriber sendCompleted ];
118
118
[compoundDisposable dispose ];
119
119
} else {
@@ -122,7 +122,7 @@ - (RACSignal *)bind:(RACSignalBindBlock (^)(void))block {
122
122
};
123
123
124
124
void (^addSignal)(RACSignal *) = ^(RACSignal *signal ) {
125
- OSAtomicIncrement32Barrier (&signalCount);
125
+ atomic_fetch_add (&signalCount, 1 );
126
126
127
127
RACSerialDisposable *selfDisposable = [[RACSerialDisposable alloc ] init ];
128
128
[compoundDisposable addDisposable: selfDisposable];
@@ -363,7 +363,7 @@ - (instancetype)filter:(BOOL (^)(id))block {
363
363
364
364
- (instancetype )flattenMap : (RACSignal *(^)(id ))block {
365
365
return [RACSignal createSignal: ^RACDisposable *(id <RACSubscriber> subscriber) {
366
- __block volatile int32_t subscriptionCount = 1 ;
366
+ __block atomic_int subscriptionCount = 1 ;
367
367
368
368
RACCompoundDisposable *disposable = [RACCompoundDisposable compoundDisposable ];
369
369
@@ -378,15 +378,15 @@ - (instancetype)flattenMap:(RACSignal *(^)(id))block {
378
378
}
379
379
NSCAssert ([signal isKindOfClass: RACSignal.class], @" Expected a RACSignal, got %@ " , signal);
380
380
381
- OSAtomicIncrement32 (&subscriptionCount);
381
+ atomic_fetch_add (&subscriptionCount, 1 );
382
382
383
383
RACDisposable *innerDisposable = [signal subscribeNext: ^(id x) {
384
384
[subscriber sendNext: x];
385
385
} error: ^(NSError *error) {
386
386
[subscriber sendError: error];
387
387
[disposable dispose ];
388
388
} completed: ^{
389
- if (! OSAtomicDecrement32 (&subscriptionCount) ) {
389
+ if (atomic_fetch_sub (&subscriptionCount, 1 ) - 1 == 0 ) {
390
390
[subscriber sendCompleted ];
391
391
}
392
392
}];
@@ -395,7 +395,7 @@ - (instancetype)flattenMap:(RACSignal *(^)(id))block {
395
395
} error: ^(NSError *error) {
396
396
[subscriber sendError: error];
397
397
} completed: ^{
398
- if (! OSAtomicDecrement32 (&subscriptionCount) ) {
398
+ if (atomic_fetch_sub (&subscriptionCount, 1 ) - 1 == 0 ) {
399
399
[subscriber sendCompleted ];
400
400
}
401
401
}];
0 commit comments