|
26 | 26 | #import "RACSubscriber.h" |
27 | 27 | #import "RACTuple.h" |
28 | 28 | #import "RACUnit.h" |
29 | | -#import <libkern/OSAtomic.h> |
| 29 | +#import <stdatomic.h> |
30 | 30 | #import <objc/runtime.h> |
31 | 31 | #import <os/lock.h> |
32 | 32 |
|
@@ -698,9 +698,9 @@ - (RACDisposable *)setKeyPath:(NSString *)keyPath onObject:(NSObject *)object ni |
698 | 698 |
|
699 | 699 | RACCompoundDisposable *disposable = [RACCompoundDisposable compoundDisposable]; |
700 | 700 |
|
701 | | - // Purposely not retaining 'object', since we want to tear down the binding |
702 | | - // when it deallocates normally. |
703 | | - __block void * volatile objectPtr = (__bridge void *)object; |
| 701 | + // Purposely not retaining 'object', since we want to tear down the binding |
| 702 | + // when it deallocates normally. |
| 703 | + __block _Atomic(void *) objectPtr = (__bridge void *)object; |
704 | 704 |
|
705 | 705 | RACDisposable *subscriptionDisposable = [self subscribeNext:^(id x) { |
706 | 706 | // Possibly spec, possibly compiler bug, but this __bridge cast does not |
@@ -750,13 +750,13 @@ - (RACDisposable *)setKeyPath:(NSString *)keyPath onObject:(NSObject *)object ni |
750 | 750 | } |
751 | 751 | #endif |
752 | 752 |
|
753 | | - while (YES) { |
754 | | - void *ptr = objectPtr; |
755 | | - if (OSAtomicCompareAndSwapPtrBarrier(ptr, NULL, &objectPtr)) { |
756 | | - break; |
757 | | - } |
758 | | - } |
759 | | - }]; |
| 753 | + while (YES) { |
| 754 | + void *ptr = objectPtr; |
| 755 | + if (atomic_compare_exchange_strong(&objectPtr, &ptr, NULL)) { |
| 756 | + break; |
| 757 | + } |
| 758 | + } |
| 759 | + }]; |
760 | 760 |
|
761 | 761 | [disposable addDisposable:clearPointerDisposable]; |
762 | 762 |
|
@@ -1150,36 +1150,36 @@ - (RACSignal *)subscribeOn:(RACScheduler *)scheduler { |
1150 | 1150 | } |
1151 | 1151 |
|
1152 | 1152 | - (RACSignal *)deliverOnMainThread { |
1153 | | - return [[RACSignal createSignal:^(id<RACSubscriber> subscriber) { |
1154 | | - __block volatile int32_t queueLength = 0; |
1155 | | - |
1156 | | - void (^performOnMainThread)(dispatch_block_t) = ^(dispatch_block_t block) { |
1157 | | - int32_t queued = OSAtomicIncrement32(&queueLength); |
1158 | | - if (NSThread.isMainThread && queued == 1) { |
1159 | | - block(); |
1160 | | - OSAtomicDecrement32(&queueLength); |
1161 | | - } else { |
1162 | | - dispatch_async(dispatch_get_main_queue(), ^{ |
1163 | | - block(); |
1164 | | - OSAtomicDecrement32(&queueLength); |
1165 | | - }); |
1166 | | - } |
1167 | | - }; |
1168 | | - |
1169 | | - return [self subscribeNext:^(id x) { |
1170 | | - performOnMainThread(^{ |
1171 | | - [subscriber sendNext:x]; |
1172 | | - }); |
1173 | | - } error:^(NSError *error) { |
1174 | | - performOnMainThread(^{ |
1175 | | - [subscriber sendError:error]; |
1176 | | - }); |
1177 | | - } completed:^{ |
1178 | | - performOnMainThread(^{ |
1179 | | - [subscriber sendCompleted]; |
1180 | | - }); |
1181 | | - }]; |
1182 | | - }] setNameWithFormat:@"[%@] -deliverOnMainThread", self.name]; |
| 1153 | + return [[RACSignal createSignal:^(id<RACSubscriber> subscriber) { |
| 1154 | + __block atomic_int queueLength = 0; |
| 1155 | + |
| 1156 | + void (^performOnMainThread)(dispatch_block_t) = ^(dispatch_block_t block) { |
| 1157 | + int32_t queued = atomic_fetch_add(&queueLength, 1) + 1; |
| 1158 | + if (NSThread.isMainThread && queued == 1) { |
| 1159 | + block(); |
| 1160 | + atomic_fetch_sub(&queueLength, 1); |
| 1161 | + } else { |
| 1162 | + dispatch_async(dispatch_get_main_queue(), ^{ |
| 1163 | + block(); |
| 1164 | + atomic_fetch_sub(&queueLength, 1); |
| 1165 | + }); |
| 1166 | + } |
| 1167 | + }; |
| 1168 | + |
| 1169 | + return [self subscribeNext:^(id x) { |
| 1170 | + performOnMainThread(^{ |
| 1171 | + [subscriber sendNext:x]; |
| 1172 | + }); |
| 1173 | + } error:^(NSError *error) { |
| 1174 | + performOnMainThread(^{ |
| 1175 | + [subscriber sendError:error]; |
| 1176 | + }); |
| 1177 | + } completed:^{ |
| 1178 | + performOnMainThread(^{ |
| 1179 | + [subscriber sendCompleted]; |
| 1180 | + }); |
| 1181 | + }]; |
| 1182 | + }] setNameWithFormat:@"[%@] -deliverOnMainThread", self.name]; |
1183 | 1183 | } |
1184 | 1184 |
|
1185 | 1185 | - (RACSignal *)groupBy:(id<NSCopying> (^)(id object))keyBlock transform:(id (^)(id object))transformBlock { |
|
0 commit comments