From 456e1df6a33d24a287c9341af4f04226ba5019a2 Mon Sep 17 00:00:00 2001 From: Michael Schneider Date: Wed, 3 Apr 2019 18:04:01 -0700 Subject: [PATCH 1/2] Use instance lock for ASPrimitiveTraitCollection --- Source/ASDisplayNode+Layout.mm | 7 +++++-- Source/Details/ASTraitCollection.h | 10 ---------- Source/Layout/ASLayoutSpec.mm | 12 +++++++++++- Source/Private/_ASCollectionGalleryLayoutItem.mm | 10 ++++++---- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/Source/ASDisplayNode+Layout.mm b/Source/ASDisplayNode+Layout.mm index 66eb99879..592b18db9 100644 --- a/Source/ASDisplayNode+Layout.mm +++ b/Source/ASDisplayNode+Layout.mm @@ -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]; } } diff --git a/Source/Details/ASTraitCollection.h b/Source/Details/ASTraitCollection.h index 68244a660..17e1740c1 100644 --- a/Source/Details/ASTraitCollection.h +++ b/Source/Details/ASTraitCollection.h @@ -106,16 +106,6 @@ AS_EXTERN void ASTraitCollectionPropagateDown(id element, ASPri @end -#define ASPrimitiveTraitCollectionDefaults \ -- (ASPrimitiveTraitCollection)primitiveTraitCollection\ -{\ - return _primitiveTraitCollection.load();\ -}\ -- (void)setPrimitiveTraitCollection:(ASPrimitiveTraitCollection)traitCollection\ -{\ - _primitiveTraitCollection = traitCollection;\ -}\ - #define ASLayoutElementCollectionTableSetTraitCollection(lock) \ - (void)setPrimitiveTraitCollection:(ASPrimitiveTraitCollection)traitCollection\ {\ diff --git a/Source/Layout/ASLayoutSpec.mm b/Source/Layout/ASLayoutSpec.mm index 8da22d3d0..2bcb92787 100644 --- a/Source/Layout/ASLayoutSpec.mm +++ b/Source/Layout/ASLayoutSpec.mm @@ -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 diff --git a/Source/Private/_ASCollectionGalleryLayoutItem.mm b/Source/Private/_ASCollectionGalleryLayoutItem.mm index 573370299..e0faa1802 100644 --- a/Source/Private/_ASCollectionGalleryLayoutItem.mm +++ b/Source/Private/_ASCollectionGalleryLayoutItem.mm @@ -14,9 +14,12 @@ #import #import -@implementation _ASGalleryLayoutItem { - std::atomic _primitiveTraitCollection; -} +@interface _ASGalleryLayoutItem () +@property ASPrimitiveTraitCollection primitiveTraitCollection; + +@end + +@implementation _ASGalleryLayoutItem @synthesize style; @@ -33,7 +36,6 @@ - (instancetype)initWithItemSize:(CGSize)itemSize collectionElement:(ASCollectio } ASLayoutElementStyleExtensibilityForwarding -ASPrimitiveTraitCollectionDefaults - (ASTraitCollection *)asyncTraitCollection { From c8335b6a3a62aad815d1ac906a8e141a9114ce75 Mon Sep 17 00:00:00 2001 From: Michael Schneider Date: Wed, 3 Apr 2019 18:05:47 -0700 Subject: [PATCH 2/2] Remove the atomic --- Source/Private/ASDisplayNodeInternal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Private/ASDisplayNodeInternal.h b/Source/Private/ASDisplayNodeInternal.h index 879639f16..0cb4f1cc7 100644 --- a/Source/Private/ASDisplayNodeInternal.h +++ b/Source/Private/ASDisplayNodeInternal.h @@ -153,7 +153,7 @@ static constexpr CACornerMask kASCACornerAllCorners = // Layout support ASLayoutElementStyle *_style; - std::atomic _primitiveTraitCollection; + ASPrimitiveTraitCollection _primitiveTraitCollection; // Layout Spec ASLayoutSpecBlock _layoutSpecBlock;