diff --git a/Crashlytics/Crashlytics/Components/FIRCLSContext.m b/Crashlytics/Crashlytics/Components/FIRCLSContext.m index 8d64268460f..327367cc97f 100644 --- a/Crashlytics/Crashlytics/Components/FIRCLSContext.m +++ b/Crashlytics/Crashlytics/Components/FIRCLSContext.m @@ -245,6 +245,10 @@ void FIRCLSContextBaseInit(void) { NSString* exceptionQueueName = [sdkBundleID stringByAppendingString:@".exception"]; _firclsLoggingQueue = dispatch_queue_create([loggingQueueName UTF8String], DISPATCH_QUEUE_SERIAL); + if (_firclsLoggingQueue) { + dispatch_queue_set_specific(_firclsLoggingQueue, &_firclsLoggingQueue, &_firclsLoggingQueue, + NULL); + } _firclsBinaryImageQueue = dispatch_queue_create([binaryImagesQueueName UTF8String], DISPATCH_QUEUE_SERIAL); _firclsExceptionQueue = @@ -437,3 +441,19 @@ bool FIRCLSContextRecordMetadata(NSString* rootPath, const FIRCLSContextInitData return true; } + +void FIRCLSExecuteOnLoggingQueue(void (^block)(void)) { + if (!block) { + return; + } + + if (!_firclsLoggingQueue) { + FIRCLSSDKLogWarn( + "FIRCLSExecuteOnLoggingQueue invoked with NULL logging queue; running block inline.\n"); + block(); + } else if (dispatch_get_specific(&_firclsLoggingQueue) != NULL) { + block(); + } else { + dispatch_sync(_firclsLoggingQueue, block); + } +} diff --git a/Crashlytics/Crashlytics/Components/FIRCLSGlobals.h b/Crashlytics/Crashlytics/Components/FIRCLSGlobals.h index 10173ed4eaf..5c5d55ee230 100644 --- a/Crashlytics/Crashlytics/Components/FIRCLSGlobals.h +++ b/Crashlytics/Crashlytics/Components/FIRCLSGlobals.h @@ -25,4 +25,6 @@ extern dispatch_queue_t _firclsExceptionQueue; #define FIRCLSGetBinaryImageQueue() (_firclsBinaryImageQueue) #define FIRCLSGetExceptionQueue() (_firclsExceptionQueue) +void FIRCLSExecuteOnLoggingQueue(void (^block)(void)); + __END_DECLS diff --git a/Crashlytics/Crashlytics/Components/FIRCLSUserLogging.m b/Crashlytics/Crashlytics/Components/FIRCLSUserLogging.m index 19a169f881a..4218e747baa 100644 --- a/Crashlytics/Crashlytics/Components/FIRCLSUserLogging.m +++ b/Crashlytics/Crashlytics/Components/FIRCLSUserLogging.m @@ -283,7 +283,7 @@ void FIRCLSUserLoggingRecordKeysAndValues(NSDictionary *keysAndValues, } } - dispatch_sync(FIRCLSGetLoggingQueue(), ^{ + FIRCLSExecuteOnLoggingQueue(^{ FIRCLSUserLoggingWriteKeysAndValues(sanitizedKeysAndValues, storage, counter, containsNullValue); }); @@ -541,7 +541,7 @@ void FIRCLSUserLoggingWriteAndCheckABFiles(FIRCLSUserLoggingABStorage *storage, } } - dispatch_sync(FIRCLSGetLoggingQueue(), ^{ + FIRCLSExecuteOnLoggingQueue(^{ FIRCLSFile file; if (!FIRCLSFileInitWithPath(&file, *activePath, true)) {