From 5c432a2bc1c5256131519c9f7925c1e9e197ee7c Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Wed, 14 Feb 2018 13:47:45 -0800 Subject: [PATCH] Fix crash on launch in debug. OWSReadReceiptManager is not `init` on the main thread; however, because it "schedules" it's own processing during init. I considered dispatching to main, but since AppReadiness already *can* resolve async if the app isn't yet ready, it should be no less safe to also dispatch async when it's off the main thread. // FREEBIE --- SignalServiceKit/src/Util/AppReadiness.m | 7 ++++--- SignalServiceKit/src/Util/Threading.h | 6 ++---- SignalServiceKit/src/Util/Threading.m | 4 ++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/SignalServiceKit/src/Util/AppReadiness.m b/SignalServiceKit/src/Util/AppReadiness.m index 95ba13e7c..44a68cfe9 100755 --- a/SignalServiceKit/src/Util/AppReadiness.m +++ b/SignalServiceKit/src/Util/AppReadiness.m @@ -3,6 +3,7 @@ // #import "AppReadiness.h" +#import "Threading.h" NS_ASSUME_NONNULL_BEGIN @@ -48,9 +49,9 @@ NS_ASSUME_NONNULL_BEGIN + (void)runNowOrWhenAppIsReady:(AppReadyBlock)block { - OWSAssertIsOnMainThread(); - - [self.sharedManager runNowOrWhenAppIsReady:block]; + DispatchMainThreadSafe(^{ + [self.sharedManager runNowOrWhenAppIsReady:block]; + }); } - (void)runNowOrWhenAppIsReady:(AppReadyBlock)block diff --git a/SignalServiceKit/src/Util/Threading.h b/SignalServiceKit/src/Util/Threading.h index 4aac9cec7..dca1d19a7 100644 --- a/SignalServiceKit/src/Util/Threading.h +++ b/SignalServiceKit/src/Util/Threading.h @@ -4,16 +4,14 @@ NS_ASSUME_NONNULL_BEGIN -typedef void (^SimpleBlock)(void); - // The block is executed immediately if called from the // main thread; otherwise it is dispatched async to the // main thread. -void DispatchMainThreadSafe(SimpleBlock block); +void DispatchMainThreadSafe(dispatch_block_t block); // The block is executed immediately if called from the // main thread; otherwise it is dispatched sync to the // main thread. -void DispatchSyncMainThreadSafe(SimpleBlock block); +void DispatchSyncMainThreadSafe(dispatch_block_t block); NS_ASSUME_NONNULL_END diff --git a/SignalServiceKit/src/Util/Threading.m b/SignalServiceKit/src/Util/Threading.m index 72505e339..be0f00501 100644 --- a/SignalServiceKit/src/Util/Threading.m +++ b/SignalServiceKit/src/Util/Threading.m @@ -6,7 +6,7 @@ NS_ASSUME_NONNULL_BEGIN -void DispatchMainThreadSafe(SimpleBlock block) +void DispatchMainThreadSafe(dispatch_block_t block) { OWSCAssert(block); @@ -19,7 +19,7 @@ void DispatchMainThreadSafe(SimpleBlock block) } } -void DispatchSyncMainThreadSafe(SimpleBlock block) +void DispatchSyncMainThreadSafe(dispatch_block_t block) { OWSCAssert(block);