From 617c22f93cb81c06c795944bcaa1b42ba54b4d04 Mon Sep 17 00:00:00 2001 From: Heberti Almeida Date: Mon, 5 Mar 2018 16:53:37 -0500 Subject: [PATCH 1/2] Fix an race condition on ASTextNode --- Source/ASTextNode.mm | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Source/ASTextNode.mm b/Source/ASTextNode.mm index e2a594b05..129e06fc7 100644 --- a/Source/ASTextNode.mm +++ b/Source/ASTextNode.mm @@ -116,10 +116,23 @@ - (BOOL)isEqual:(ASTextNodeRendererKey *)object key.attributes = attributes; key.constrainedSize = constrainedSize; - ASTextKitRenderer *renderer = [cache objectForKey:key]; + static dispatch_queue_t rendererQueue; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + rendererQueue = dispatch_queue_create("org.AsyncDisplayKit.ASTextNode.renderer", DISPATCH_QUEUE_CONCURRENT); + dispatch_set_target_queue(rendererQueue, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)); + }); + + __block ASTextKitRenderer *renderer; + dispatch_sync(rendererQueue, ^{ + renderer = [cache objectForKey:key]; + }); + if (renderer == nil) { renderer = [[ASTextKitRenderer alloc] initWithTextKitAttributes:attributes constrainedSize:constrainedSize]; - [cache setObject:renderer forKey:key]; + dispatch_barrier_async(rendererQueue, ^{ + [cache setObject:renderer forKey:key]; + }); } return renderer; From f01845ff916af58a060c73722afc5982b186953d Mon Sep 17 00:00:00 2001 From: Heberti Almeida Date: Mon, 5 Mar 2018 19:47:06 -0500 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60ab5ecd9..f5ab743b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## master * Add your own contributions to the next release on the line below this with your name. +- [ASTextNode] Fix an race condition on ASTextKitAttributes [Heberti Almeida](http://github.com/hebertialmeida) [#819] - [ASDisplayNode] Add unit tests for layout z-order changes (with an open issue to fix). - [ASDisplayNode] Consolidate main thread initialization and allow apps to invoke it manually instead of +load. - [ASRunloopQueue] Introduce new runloop queue(ASCATransactionQueue) to coalesce Interface state update calls for view controller transitions.