From a61583c258ade5a35a020fdff41e17b9bba13cf5 Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Sun, 11 Mar 2018 13:42:28 -0700 Subject: [PATCH 1/3] Fix thread sanitizer warning in ASTextNodeRendererKey --- Source/ASTextNode.mm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Source/ASTextNode.mm b/Source/ASTextNode.mm index ccbed9c07..884b6ca4c 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 { @@ -85,8 +88,13 @@ - (BOOL)isEqual:(ASTextNodeRendererKey *)object if (self == object) { return YES; } + + // 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); + return _attributes == object->_attributes && CGSizeEqualToSize(_constrainedSize, object->_constrainedSize); } @end From 3922430f0fb718435b57ac11cfaad62d22ce4125 Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Sun, 11 Mar 2018 13:44:28 -0700 Subject: [PATCH 2/3] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60ab5ecd9..3b65396c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,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) From 0517d78b4696409b075074515c49b1afb8551e8a Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Mon, 12 Mar 2018 10:40:57 -0700 Subject: [PATCH 3/3] Comment on missing class check --- Source/ASTextNode.mm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/ASTextNode.mm b/Source/ASTextNode.mm index 884b6ca4c..a0662516e 100644 --- a/Source/ASTextNode.mm +++ b/Source/ASTextNode.mm @@ -88,6 +88,8 @@ - (BOOL)isEqual:(ASTextNodeRendererKey *)object if (self == object) { return YES; } + + // NOTE: Skip the class check for this specialized, internal Key object. // Lock both objects, avoiding deadlock. std::lock(_m, object->_m);