From 3a624ed0e974b58258f770a1b34201f3a478f3b9 Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Mon, 12 Mar 2018 10:42:24 -0700 Subject: [PATCH] Fix Text Node Thread Sanitizer Warning (#830) * Fix thread sanitizer warning in ASTextNodeRendererKey * Update changelog * Comment on missing class check --- CHANGELOG.md | 1 + Source/ASTextNode.mm | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 466623147..8889c2696 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ - Pass scrollViewWillEndDragging delegation through in ASIGListAdapterDataSource for IGListKit integration. [#796](https://github.com/TextureGroup/Texture/pull/796) - Fix UIResponder handling with view backing ASDisplayNode. [Michael Schneider](https://github.com/maicki) [#789] (https://github.com/TextureGroup/Texture/pull/789/) - Optimized thread-local storage by replacing pthread_specific with C11 thread-local variables. [Adlai Holler](https://github.com/Adlai-Holler) [#811] (https://github.com/TextureGroup/Texture/pull/811/) +- Fixed a thread-sanitizer warning in ASTextNode. [Adlai Holler](https://github.com/Adlai-Holler) [#830] (https://github.com/TextureGroup/Texture/pull/830/) ## 2.6 - [Xcode 9] Updated to require Xcode 9 (to fix warnings) [Garrett Moon](https://github.com/garrettmoon) diff --git a/Source/ASTextNode.mm b/Source/ASTextNode.mm index 768223070..0b6421e7a 100644 --- a/Source/ASTextNode.mm +++ b/Source/ASTextNode.mm @@ -63,10 +63,13 @@ @interface ASTextNodeRendererKey : NSObject @property (assign, nonatomic) CGSize constrainedSize; @end -@implementation ASTextNodeRendererKey +@implementation ASTextNodeRendererKey { + std::mutex _m; +} - (NSUInteger)hash { + std::lock_guard _l(_m); #pragma clang diagnostic push #pragma clang diagnostic warning "-Wpadded" struct { @@ -86,7 +89,14 @@ - (BOOL)isEqual:(ASTextNodeRendererKey *)object return YES; } - return _attributes == object.attributes && CGSizeEqualToSize(_constrainedSize, object.constrainedSize); + // NOTE: Skip the class check for this specialized, internal Key object. + + // Lock both objects, avoiding deadlock. + std::lock(_m, object->_m); + std::lock_guard lk1(_m, std::adopt_lock); + std::lock_guard lk2(object->_m, std::adopt_lock); + + return _attributes == object->_attributes && CGSizeEqualToSize(_constrainedSize, object->_constrainedSize); } @end