11
11
#import " RACDisposable.h"
12
12
#import " RACSerialDisposable.h"
13
13
#import " RACSubject.h"
14
- #import < libkern/OSAtomic .h>
14
+ #import < stdatomic .h>
15
15
16
16
@interface RACMulticastConnection () {
17
17
RACSubject *_signal;
@@ -24,7 +24,7 @@ @interface RACMulticastConnection () {
24
24
//
25
25
// If the swap is unsuccessful it means that `_sourceSignal` has already been
26
26
// connected and the caller has no action to take.
27
- int32_t volatile _hasConnected;
27
+ _Atomic ( BOOL ) _hasConnected;
28
28
}
29
29
30
30
@property (nonatomic , readonly , strong ) RACSignal *sourceSignal;
@@ -51,7 +51,8 @@ - (instancetype)initWithSourceSignal:(RACSignal *)source subject:(RACSubject *)s
51
51
#pragma mark Connecting
52
52
53
53
- (RACDisposable *)connect {
54
- BOOL shouldConnect = OSAtomicCompareAndSwap32Barrier (0 , 1 , &_hasConnected);
54
+ BOOL expected = NO ;
55
+ BOOL shouldConnect = atomic_compare_exchange_strong (&_hasConnected, &expected, YES );
55
56
56
57
if (shouldConnect) {
57
58
self.serialDisposable .disposable = [self .sourceSignal subscribe: _signal];
@@ -61,19 +62,19 @@ - (RACDisposable *)connect {
61
62
}
62
63
63
64
- (RACSignal *)autoconnect {
64
- __block volatile int32_t subscriberCount = 0 ;
65
+ __block atomic_int subscriberCount = 0 ;
65
66
66
67
return [[RACSignal
67
68
createSignal: ^(id <RACSubscriber> subscriber) {
68
- OSAtomicIncrement32Barrier (&subscriberCount);
69
+ atomic_fetch_add (&subscriberCount, 1 );
69
70
70
71
RACDisposable *subscriptionDisposable = [self .signal subscribe: subscriber];
71
72
RACDisposable *connectionDisposable = [self connect ];
72
73
73
74
return [RACDisposable disposableWithBlock: ^{
74
75
[subscriptionDisposable dispose ];
75
76
76
- if (OSAtomicDecrement32Barrier (&subscriberCount) == 0 ) {
77
+ if (atomic_fetch_sub (&subscriberCount, 1 ) - 1 == 0 ) {
77
78
[connectionDisposable dispose ];
78
79
}
79
80
}];
0 commit comments