Guard from hooking modules twice

Summary: public

The dev menu is a little bit flaky right now, and sometimes it emits messages twice,
so guard it not to hook into the modules twice.

Reviewed By: jspahrsummers

Differential Revision: D2625911

fb-gh-sync-id: 18fd6bc00e473ed226291e7aca4a02cec84bfc8f
This commit is contained in:
Tadeu Zagallo 2015-11-07 13:46:35 -08:00 committed by facebook-github-bot-3
parent 2db10e3e72
commit 1f0d48a0e4
1 changed files with 12 additions and 1 deletions

View File

@ -38,7 +38,10 @@ NSString *const RCTProfilePrefix = @"rct_profile_";
#pragma mark - Variables
// This is actually a BOOL - but has to be compatible with OSAtomic
static volatile uint32_t RCTProfileProfiling;
static BOOL RCTProfileHookedModules;
static NSDictionary *RCTProfileInfo;
static NSMutableDictionary *RCTProfileOngoingEvents;
static NSTimeInterval RCTProfileStartTime;
@ -200,11 +203,13 @@ void RCTProfileHookModules(RCTBridge *bridge)
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wtautological-pointer-compare"
if (RCTProfileTrampoline == NULL) {
if (RCTProfileTrampoline == NULL || RCTProfileHookedModules) {
return;
}
#pragma clang diagnostic pop
RCTProfileHookedModules = YES;
for (RCTModuleData *moduleData in [bridge valueForKey:@"moduleDataByID"]) {
[moduleData dispatchBlock:^{
Class moduleClass = moduleData.moduleClass;
@ -243,6 +248,12 @@ void RCTProfileHookModules(RCTBridge *bridge)
void RCTProfileUnhookModules(RCTBridge *bridge)
{
if (!RCTProfileHookedModules) {
return;
}
RCTProfileHookedModules = NO;
dispatch_group_enter(RCTProfileGetUnhookGroup());
for (RCTModuleData *moduleData in [bridge valueForKey:@"moduleDataByID"]) {