Permalink
Browse files

RCTProfile: Use C atomics instead of OSAtomic

Summary:
This will save us precious microseconds and it's prettier to look at.
Closes #15276

Differential Revision: D5531823

Pulled By: javache

fbshipit-source-id: f8a97ec2a03e3cfdf1801457a481ec62a9371eeb
  • Loading branch information...
Adlai-Holler authored and facebook-github-bot committed Aug 1, 2017
1 parent c1c791f commit 24df099835dc6482fcf46c5fa9ed033de4e9d4a9
Showing with 7 additions and 11 deletions.
  1. +7 −11 React/Profiler/RCTProfile.m
@@ -10,7 +10,7 @@
#import "RCTProfile.h"
#import <dlfcn.h>
#import <libkern/OSAtomic.h>
#import <stdatomic.h>
#import <mach/mach.h>
#import <objc/message.h>
#import <objc/runtime.h>
@@ -42,8 +42,7 @@
#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];

0 comments on commit 24df099

Please sign in to comment.