1111#import " RACDisposable.h"
1212#import " RACSerialDisposable.h"
1313#import " RACSubject.h"
14- #import < libkern/OSAtomic .h>
14+ #import < stdatomic .h>
1515
1616@interface RACMulticastConnection () {
1717 RACSubject *_signal;
@@ -24,7 +24,7 @@ @interface RACMulticastConnection () {
2424 //
2525 // If the swap is unsuccessful it means that `_sourceSignal` has already been
2626 // connected and the caller has no action to take.
27- int32_t volatile _hasConnected;
27+ _Atomic ( BOOL ) _hasConnected;
2828}
2929
3030@property (nonatomic , readonly , strong ) RACSignal *sourceSignal;
@@ -51,7 +51,8 @@ - (instancetype)initWithSourceSignal:(RACSignal *)source subject:(RACSubject *)s
5151#pragma mark Connecting
5252
5353- (RACDisposable *)connect {
54- BOOL shouldConnect = OSAtomicCompareAndSwap32Barrier (0 , 1 , &_hasConnected);
54+ BOOL expected = NO ;
55+ BOOL shouldConnect = atomic_compare_exchange_strong (&_hasConnected, &expected, YES );
5556
5657 if (shouldConnect) {
5758 self.serialDisposable .disposable = [self .sourceSignal subscribe: _signal];
@@ -61,19 +62,19 @@ - (RACDisposable *)connect {
6162}
6263
6364- (RACSignal *)autoconnect {
64- __block volatile int32_t subscriberCount = 0 ;
65+ __block atomic_int subscriberCount = 0 ;
6566
6667 return [[RACSignal
6768 createSignal: ^(id <RACSubscriber> subscriber) {
68- OSAtomicIncrement32Barrier (&subscriberCount);
69+ atomic_fetch_add (&subscriberCount, 1 );
6970
7071 RACDisposable *subscriptionDisposable = [self .signal subscribe: subscriber];
7172 RACDisposable *connectionDisposable = [self connect ];
7273
7374 return [RACDisposable disposableWithBlock: ^{
7475 [subscriptionDisposable dispose ];
7576
76- if (OSAtomicDecrement32Barrier (&subscriberCount) == 0 ) {
77+ if (atomic_fetch_sub (&subscriberCount, 1 ) - 1 == 0 ) {
7778 [connectionDisposable dispose ];
7879 }
7980 }];
0 commit comments