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

[ASTraitCollection] Convert ASPrimitiveTraitCollection from lock to atomic. #355

Merged
merged 2 commits into from
Jun 14, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
@@ -1,6 +1,7 @@
## master

* Add your own contributions to the next release on the line below this with your name.
- [ASTraitCollection] Convert ASPrimitiveTraitCollection from lock to atomic. [Scott Goodson](https://github.com/appleguy)
- Add a synchronous mode to ASCollectionNode, for colletion view data source debugging. [Hannah Troisi](https://github.com/hannahmbanana)
- [ASDisplayNode+Layout] Add check for orphaned nodes after layout transition to clean up. #336. [Scott Goodson](https://github.com/appleguy)
- Fixed an issue where GIFs with placeholders never had their placeholders uncover the GIF. [Garrett Moon](https://github.com/garrettmoon)
Expand Down
15 changes: 4 additions & 11 deletions Source/ASDisplayNode+Layout.mm
Original file line number Diff line number Diff line change
Expand Up @@ -98,28 +98,21 @@ - (ASLayout *)layoutThatFits:(ASSizeRange)constrainedSize parentSize:(CGSize)par

- (ASPrimitiveTraitCollection)primitiveTraitCollection
{
ASDN::MutexLocker l(__instanceLock__);
return _primitiveTraitCollection;
return _primitiveTraitCollection.load();
}

- (void)setPrimitiveTraitCollection:(ASPrimitiveTraitCollection)traitCollection
{
__instanceLock__.lock();
if (ASPrimitiveTraitCollectionIsEqualToASPrimitiveTraitCollection(traitCollection, _primitiveTraitCollection) == NO) {
_primitiveTraitCollection = traitCollection;
if (ASPrimitiveTraitCollectionIsEqualToASPrimitiveTraitCollection(traitCollection, _primitiveTraitCollection.load()) == NO) {
_primitiveTraitCollection.store(traitCollection);
ASDisplayNodeLogEvent(self, @"asyncTraitCollectionDidChange: %@", NSStringFromASPrimitiveTraitCollection(traitCollection));
__instanceLock__.unlock();


[self asyncTraitCollectionDidChange];
return;
}

__instanceLock__.unlock();
}

- (ASTraitCollection *)asyncTraitCollection
{
ASDN::MutexLocker l(__instanceLock__);
return [ASTraitCollection traitCollectionWithASPrimitiveTraitCollection:self.primitiveTraitCollection];
}

Expand Down
4 changes: 2 additions & 2 deletions Source/Details/ASTraitCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ ASDISPLAYNODE_EXTERN_C_END
#define ASPrimitiveTraitCollectionDefaults \
- (ASPrimitiveTraitCollection)primitiveTraitCollection\
{\
return _primitiveTraitCollection;\
return _primitiveTraitCollection.load();\
}\
- (void)setPrimitiveTraitCollection:(ASPrimitiveTraitCollection)traitCollection\
{\
_primitiveTraitCollection = traitCollection;\
_primitiveTraitCollection.store(traitCollection);\
}\

#define ASPrimitiveTraitCollectionDeprecatedImplementation \
Expand Down
2 changes: 1 addition & 1 deletion Source/Layout/ASLayoutSpec.mm
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ - (instancetype)init
}

_isMutable = YES;
_primitiveTraitCollection = ASPrimitiveTraitCollectionMakeDefault();
_primitiveTraitCollection.store(ASPrimitiveTraitCollectionMakeDefault());
_childrenArray = [[NSMutableArray alloc] init];

return self;
Expand Down
2 changes: 1 addition & 1 deletion Source/Private/ASDisplayNodeInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ FOUNDATION_EXPORT NSString * const ASRenderingEngineDidDisplayNodesScheduledBefo
NSArray<ASDisplayNode *> *_cachedSubnodes;

ASLayoutElementStyle *_style;
ASPrimitiveTraitCollection _primitiveTraitCollection;
std::atomic<ASPrimitiveTraitCollection> _primitiveTraitCollection;

std::atomic_uint _displaySentinel;

Expand Down
2 changes: 1 addition & 1 deletion Source/Private/Layout/ASLayoutSpecPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ NS_ASSUME_NONNULL_BEGIN

@interface ASLayoutSpec() {
ASDN::RecursiveMutex __instanceLock__;
ASPrimitiveTraitCollection _primitiveTraitCollection;
std::atomic <ASPrimitiveTraitCollection> _primitiveTraitCollection;
ASLayoutElementStyle *_style;
NSMutableArray *_childrenArray;
}
Expand Down