From fdbc1e03dec48984483dd6e74acee25e773c82b5 Mon Sep 17 00:00:00 2001 From: Tadeu Zagallo Date: Mon, 9 Nov 2015 08:02:46 -0800 Subject: [PATCH] Use barrier to write flag Summary: public Use OSAtomicBarrier to write the flags rather than using OSAtomic to read *and* write. Reviewed By: jspahrsummers Differential Revision: D2625915 fb-gh-sync-id: 2ed357ae408b2afe5ef2689582585bf4f9edd8a7 --- React/Profiler/RCTProfile.m | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/React/Profiler/RCTProfile.m b/React/Profiler/RCTProfile.m index d0b11d996..b2ce5b87a 100644 --- a/React/Profiler/RCTProfile.m +++ b/React/Profiler/RCTProfile.m @@ -282,14 +282,18 @@ dispatch_queue_t RCTProfileGetQueue(void) BOOL RCTProfileIsProfiling(void) { - return (BOOL)OSAtomicAnd32(1, &RCTProfileProfiling); + return (BOOL)RCTProfileProfiling; } void RCTProfileInit(RCTBridge *bridge) { // TODO: enable assert JS thread from any file (and assert here) - OSAtomicOr32(1, &RCTProfileProfiling); + if (RCTProfileIsProfiling()) { + return; + } + + OSAtomicOr32Barrier(1, &RCTProfileProfiling); if (callbacks != NULL) { size_t buffer_size = 1 << 22; @@ -321,7 +325,7 @@ void RCTProfileEnd(RCTBridge *bridge, void (^callback)(NSString *)) return; } - OSAtomicAnd32(0, &RCTProfileProfiling); + OSAtomicAnd32Barrier(0, &RCTProfileProfiling); [[NSNotificationCenter defaultCenter] postNotificationName:RCTProfileDidEndProfiling object:nil];