Skip to content

Commit

Permalink
Fix Text Node Thread Sanitizer Warning (TextureGroup#830)
Browse files Browse the repository at this point in the history
* Fix thread sanitizer warning in ASTextNodeRendererKey

* Update changelog

* Comment on missing class check
  • Loading branch information
Adlai-Holler authored and bernieperez committed Apr 25, 2018
1 parent c22a082 commit 3a624ed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 12 additions & 2 deletions Source/ASTextNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::mutex> _l(_m);
#pragma clang diagnostic push
#pragma clang diagnostic warning "-Wpadded"
struct {
Expand All @@ -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<std::mutex> lk1(_m, std::adopt_lock);
std::lock_guard<std::mutex> lk2(object->_m, std::adopt_lock);

return _attributes == object->_attributes && CGSizeEqualToSize(_constrainedSize, object->_constrainedSize);
}

@end
Expand Down

0 comments on commit 3a624ed

Please sign in to comment.