Skip to content

Commit 3fb0e18

Browse files
maickiappleguy
authored andcommitted
[ASTextNode] Further locking improvements for ASTextNode (facebookarchive#1813)
* Further locking improvements for ASTextNode * Remove tighter holding of lock as this operation needs to complete with the lock held
1 parent 77f2423 commit 3fb0e18

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

AsyncDisplayKit/ASTextNode.mm

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,8 @@ - (void)calculatedLayoutDidChange
326326

327327
ASLayout *layout = self.calculatedLayout;
328328

329-
std::lock_guard<std::recursive_mutex> l(_textLock);
330329
if (layout != nil) {
330+
std::lock_guard<std::recursive_mutex> l(_textLock);
331331
_constrainedSize = layout.size;
332332
_renderer.constrainedSize = layout.size;
333333
}
@@ -713,6 +713,8 @@ - (void)_setHighlightRange:(NSRange)highlightRange forAttributeName:(NSString *)
713713
}
714714

715715
if (highlightTargetLayer != nil) {
716+
std::lock_guard<std::recursive_mutex> l(_textLock);
717+
716718
NSArray *highlightRects = [[self _renderer] rectsForTextRange:highlightRange measureOption:ASTextKitRendererMeasureOptionBlock];
717719
NSMutableArray *converted = [NSMutableArray arrayWithCapacity:highlightRects.count];
718720
for (NSValue *rectValue in highlightRects) {
@@ -906,8 +908,6 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
906908
{
907909
ASDisplayNodeAssertMainThread();
908910

909-
std::lock_guard<std::recursive_mutex> l(_textLock);
910-
911911
[super touchesBegan:touches withEvent:event];
912912

913913
CGPoint point = [[touches anyObject] locationInView:self.view];
@@ -926,7 +926,11 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
926926
BOOL linkCrossesVisibleRange = (lastCharIndex > range.location) && (lastCharIndex < NSMaxRange(range) - 1);
927927

928928
if (inAdditionalTruncationMessage) {
929-
NSRange visibleRange = [self _renderer].firstVisibleRange;
929+
NSRange visibleRange = NSMakeRange(0, 0);
930+
{
931+
std::lock_guard<std::recursive_mutex> l(_textLock);
932+
visibleRange = [self _renderer].firstVisibleRange;
933+
}
930934
NSRange truncationMessageRange = [self _additionalTruncationMessageRangeWithVisibleRange:visibleRange];
931935
[self _setHighlightRange:truncationMessageRange forAttributeName:ASTextNodeTruncationTokenAttributeName value:nil animated:YES];
932936
} else if (range.length && !linkCrossesVisibleRange && linkAttributeValue != nil && linkAttributeName != nil) {

0 commit comments

Comments
 (0)