2323#import " RACSubject.h"
2424#import " RACSubscriber+Private.h"
2525#import " RACTuple.h"
26- #import < libkern/OSAtomic .h>
26+ #import < stdatomic .h>
2727
2828@implementation RACSignal
2929
@@ -108,12 +108,12 @@ - (RACSignal *)bind:(RACSignalBindBlock (^)(void))block {
108108 return [[RACSignal createSignal: ^(id <RACSubscriber> subscriber) {
109109 RACSignalBindBlock bindingBlock = block ();
110110
111- __block volatile int32_t signalCount = 1 ; // indicates self
111+ __block atomic_int signalCount = 1 ; // indicates self
112112
113113 RACCompoundDisposable *compoundDisposable = [RACCompoundDisposable compoundDisposable ];
114114
115115 void (^completeSignal)(RACDisposable *) = ^(RACDisposable *finishedDisposable) {
116- if (OSAtomicDecrement32Barrier (&signalCount) == 0 ) {
116+ if (atomic_fetch_sub (&signalCount, 1 ) - 1 == 0 ) {
117117 [subscriber sendCompleted ];
118118 [compoundDisposable dispose ];
119119 } else {
@@ -122,7 +122,7 @@ - (RACSignal *)bind:(RACSignalBindBlock (^)(void))block {
122122 };
123123
124124 void (^addSignal)(RACSignal *) = ^(RACSignal *signal) {
125- OSAtomicIncrement32Barrier (&signalCount);
125+ atomic_fetch_add (&signalCount, 1 );
126126
127127 RACSerialDisposable *selfDisposable = [[RACSerialDisposable alloc ] init ];
128128 [compoundDisposable addDisposable: selfDisposable];
@@ -363,7 +363,7 @@ - (instancetype)filter:(BOOL (^)(id))block {
363363
364364- (instancetype )flattenMap : (RACSignal *(^)(id ))block {
365365 return [RACSignal createSignal: ^RACDisposable *(id <RACSubscriber> subscriber) {
366- __block volatile int32_t subscriptionCount = 1 ;
366+ __block atomic_int subscriptionCount = 1 ;
367367
368368 RACCompoundDisposable *disposable = [RACCompoundDisposable compoundDisposable ];
369369
@@ -378,15 +378,15 @@ - (instancetype)flattenMap:(RACSignal *(^)(id))block {
378378 }
379379 NSCAssert ([signal isKindOfClass: RACSignal.class], @" Expected a RACSignal, got %@ " , signal);
380380
381- OSAtomicIncrement32 (&subscriptionCount);
381+ atomic_fetch_add (&subscriptionCount, 1 );
382382
383383 RACDisposable *innerDisposable = [signal subscribeNext: ^(id x) {
384384 [subscriber sendNext: x];
385385 } error: ^(NSError *error) {
386386 [subscriber sendError: error];
387387 [disposable dispose ];
388388 } completed: ^{
389- if (! OSAtomicDecrement32 (&subscriptionCount) ) {
389+ if (atomic_fetch_sub (&subscriptionCount, 1 ) - 1 == 0 ) {
390390 [subscriber sendCompleted ];
391391 }
392392 }];
@@ -395,7 +395,7 @@ - (instancetype)flattenMap:(RACSignal *(^)(id))block {
395395 } error: ^(NSError *error) {
396396 [subscriber sendError: error];
397397 } completed: ^{
398- if (! OSAtomicDecrement32 (&subscriptionCount) ) {
398+ if (atomic_fetch_sub (&subscriptionCount, 1 ) - 1 == 0 ) {
399399 [subscriber sendCompleted ];
400400 }
401401 }];
0 commit comments