diff --git a/React/Profiler/RCTProfile.m b/React/Profiler/RCTProfile.m index 10ce57128..a69e73a62 100644 --- a/React/Profiler/RCTProfile.m +++ b/React/Profiler/RCTProfile.m @@ -10,7 +10,7 @@ #import "RCTProfile.h" #import -#import +#import #import #import #import @@ -42,8 +42,7 @@ static NSString *const kProfilePrefix = @"rct_profile_"; #pragma mark - Variables -// This is actually a BOOL - but has to be compatible with OSAtomic -static volatile uint32_t RCTProfileProfiling; +static atomic_bool RCTProfileProfiling = ATOMIC_VAR_INIT(NO); static NSDictionary *RCTProfileInfo; static NSMutableDictionary *RCTProfileOngoingEvents; @@ -439,18 +438,17 @@ dispatch_queue_t RCTProfileGetQueue(void) BOOL RCTProfileIsProfiling(void) { - return (BOOL)RCTProfileProfiling; + return atomic_load(&RCTProfileProfiling); } void RCTProfileInit(RCTBridge *bridge) { // TODO: enable assert JS thread from any file (and assert here) - if (RCTProfileIsProfiling()) { + BOOL wasProfiling = atomic_fetch_or(&RCTProfileProfiling, 1); + if (wasProfiling) { return; } - OSAtomicOr32Barrier(1, &RCTProfileProfiling); - if (callbacks != NULL) { systrace_buffer = callbacks->start(); } else { @@ -493,13 +491,11 @@ void RCTProfileInit(RCTBridge *bridge) void RCTProfileEnd(RCTBridge *bridge, void (^callback)(NSString *)) { // assert JavaScript thread here again - - if (!RCTProfileIsProfiling()) { + BOOL wasProfiling = atomic_fetch_and(&RCTProfileProfiling, 0); + if (!wasProfiling) { return; } - OSAtomicAnd32Barrier(0, &RCTProfileProfiling); - [[NSNotificationCenter defaultCenter] postNotificationName:RCTProfileDidEndProfiling object:bridge];