Introducing RCTAssertUIManagerQueue()

Reviewed By: javache

Differential Revision: D4868564

fbshipit-source-id: b9b9f6cf8f31495bb0e82fb60b2402dde460ddb8
This commit is contained in:
Valentin Shergin 2017-05-08 12:40:06 -07:00 committed by Facebook Github Bot
parent bd004568d3
commit 2a984326b0
3 changed files with 23 additions and 2 deletions

View File

@ -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

View File

@ -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.

View File

@ -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();