Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Text Node Thread Sanitizer Warning #830

Merged
merged 3 commits into from
Mar 12, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 10 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 @@ -85,8 +88,13 @@ - (BOOL)isEqual:(ASTextNodeRendererKey *)object
if (self == object) {
return YES;
}

// Lock both objects, avoiding deadlock.
std::lock(_m, object->_m);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to you changes, should there be class checks in here? It may not matter in since this is an internal object, but should we ensure object is an ASTextRendererKey for correctness?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. I added a comment explaining it.

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);
return _attributes == object->_attributes && CGSizeEqualToSize(_constrainedSize, object->_constrainedSize);
}

@end
Expand Down