diff --git a/React/Base/RCTAssert.h b/React/Base/RCTAssert.h index c3c0008f2..0cd76b241 100644 --- a/React/Base/RCTAssert.h +++ b/React/Base/RCTAssert.h @@ -85,13 +85,13 @@ typedef void (^RCTFatalHandler)(NSError *error); * Convenience macro for asserting that we're running on main queue. */ #define RCTAssertMainQueue() RCTAssert(RCTIsMainQueue(), \ - @"This function must be called on the main thread") + @"This function must be called on the main queue") /** * Convenience macro for asserting that we're running off the main queue. */ #define RCTAssertNotMainQueue() RCTAssert(!RCTIsMainQueue(), \ -@"This function must not be called on the main thread") +@"This function must not be called on the main queue") /** * Deprecated, do not use diff --git a/React/Modules/RCTUIManager.h b/React/Modules/RCTUIManager.h index e65f889b8..2079082ba 100644 --- a/React/Modules/RCTUIManager.h +++ b/React/Modules/RCTUIManager.h @@ -25,6 +25,17 @@ RCT_EXTERN dispatch_queue_t RCTGetUIManagerQueue(void); */ RCT_EXTERN char *const RCTUIManagerQueueName; +/** + * Check if we are currently on UIManager queue. + */ +RCT_EXTERN BOOL RCTIsUIManagerQueue(void); + +/** + * Convenience macro for asserting that we're running on UIManager queue. + */ +#define RCTAssertUIManagerQueue() RCTAssert(RCTIsUIManagerQueue(), \ +@"This function must be called on the UIManager queue") + /** * Posted right before re-render happens. This is a chance for views to invalidate their state so * next render cycle will pick up updated views and layout appropriately. diff --git a/React/Modules/RCTUIManager.m b/React/Modules/RCTUIManager.m index 38d093022..56e54e474 100644 --- a/React/Modules/RCTUIManager.m +++ b/React/Modules/RCTUIManager.m @@ -345,6 +345,16 @@ dispatch_queue_t RCTGetUIManagerQueue(void) return shadowQueue; } +BOOL RCTIsUIManagerQueue() +{ + static void *queueKey = &queueKey; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + dispatch_queue_set_specific(RCTGetUIManagerQueue(), queueKey, queueKey, NULL); + }); + return dispatch_get_specific(queueKey) == queueKey; +} + - (dispatch_queue_t)methodQueue { return RCTGetUIManagerQueue();