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

Use instance lock for ASPrimitiveTraitCollection #1442

Merged
merged 2 commits into from
Apr 4, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 5 additions & 2 deletions Source/ASDisplayNode+Layout.mm
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,18 @@ - (ASLayout *)layoutThatFits:(ASSizeRange)constrainedSize parentSize:(CGSize)par

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

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

l.unlock();
[self asyncTraitCollectionDidChange];
}
}
Expand Down
10 changes: 0 additions & 10 deletions Source/Details/ASTraitCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,6 @@ AS_EXTERN void ASTraitCollectionPropagateDown(id<ASLayoutElement> element, ASPri

@end

#define ASPrimitiveTraitCollectionDefaults \
- (ASPrimitiveTraitCollection)primitiveTraitCollection\
{\
return _primitiveTraitCollection.load();\
}\
- (void)setPrimitiveTraitCollection:(ASPrimitiveTraitCollection)traitCollection\
{\
_primitiveTraitCollection = traitCollection;\
}\

#define ASLayoutElementCollectionTableSetTraitCollection(lock) \
- (void)setPrimitiveTraitCollection:(ASPrimitiveTraitCollection)traitCollection\
{\
Expand Down
12 changes: 11 additions & 1 deletion Source/Layout/ASLayoutSpec.mm
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,17 @@ - (ASTraitCollection *)asyncTraitCollection
return [ASTraitCollection traitCollectionWithASPrimitiveTraitCollection:self.primitiveTraitCollection];
}

ASPrimitiveTraitCollectionDefaults
- (ASPrimitiveTraitCollection)primitiveTraitCollection
{
AS::MutexLocker l(__instanceLock__);
return _primitiveTraitCollection;
}

- (void)setPrimitiveTraitCollection:(ASPrimitiveTraitCollection)traitCollection
{
AS::MutexLocker l(__instanceLock__);
_primitiveTraitCollection = traitCollection;
}

#pragma mark - ASLayoutElementStyleExtensibility

Expand Down
2 changes: 1 addition & 1 deletion Source/Private/ASDisplayNodeInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ static constexpr CACornerMask kASCACornerAllCorners =

// Layout support
ASLayoutElementStyle *_style;
std::atomic<ASPrimitiveTraitCollection> _primitiveTraitCollection;
ASPrimitiveTraitCollection _primitiveTraitCollection;

// Layout Spec
ASLayoutSpecBlock _layoutSpecBlock;
Expand Down
10 changes: 6 additions & 4 deletions Source/Private/_ASCollectionGalleryLayoutItem.mm
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
#import <AsyncDisplayKit/ASLayoutElementStylePrivate.h>
#import <AsyncDisplayKit/ASLayoutSpec.h>

@implementation _ASGalleryLayoutItem {
std::atomic<ASPrimitiveTraitCollection> _primitiveTraitCollection;
}
@interface _ASGalleryLayoutItem ()
@property ASPrimitiveTraitCollection primitiveTraitCollection;

@end

@implementation _ASGalleryLayoutItem

@synthesize style;

Expand All @@ -33,7 +36,6 @@ - (instancetype)initWithItemSize:(CGSize)itemSize collectionElement:(ASCollectio
}

ASLayoutElementStyleExtensibilityForwarding
ASPrimitiveTraitCollectionDefaults

- (ASTraitCollection *)asyncTraitCollection
{
Expand Down