Skip to content

Commit

Permalink
Merge branch 'master' into AHRenamespace
Browse files Browse the repository at this point in the history
  • Loading branch information
Adlai-Holler authored Mar 7, 2019
2 parents 6ace1ba + fce6f23 commit b2bcd0f
Show file tree
Hide file tree
Showing 21 changed files with 202 additions and 170 deletions.
1 change: 0 additions & 1 deletion Schemas/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"exp_interface_state_coalesce",
"exp_unfair_lock",
"exp_infer_layer_defaults",
"exp_network_image_queue",
"exp_collection_teardown",
"exp_framesetter_cache",
"exp_skip_clear_data",
Expand Down
33 changes: 1 addition & 32 deletions Source/ASDisplayNode+Layout.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1048,10 +1048,7 @@ - (void)_locked_setCalculatedDisplayNodeLayout:(const ASDisplayNodeLayout &)disp
#pragma mark -
#pragma mark - ASDisplayNode (YogaLayout)

@implementation ASDisplayNode (YogaInternal)

#pragma mark -
#pragma mark - ASDisplayNode (Yoga)
@implementation ASDisplayNode (YogaLayout)

- (BOOL)locked_shouldLayoutFromYogaRoot {
#if YOGA
Expand All @@ -1073,32 +1070,4 @@ - (BOOL)locked_shouldLayoutFromYogaRoot {
#endif
}

- (ASLockSet)lockToRootIfNeededForLayout {
ASLockSet lockSet = ASLockSequence(^BOOL(ASAddLockBlock addLock) {
if (!addLock(self)) {
return NO;
}
#if YOGA
if (![self locked_shouldLayoutFromYogaRoot]) {
return YES;
}
if (self.nodeController && !addLock(self.nodeController)) {
return NO;
}
ASDisplayNode *parent = _supernode;
while (parent) {
if (!addLock(parent)) {
return NO;
}
if (parent.nodeController && !addLock(parent.nodeController)) {
return NO;
}
parent = parent->_supernode;
}
#endif
return true;
});
return lockSet;
}

@end
4 changes: 4 additions & 0 deletions Source/ASDisplayNode+Yoga.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ AS_EXTERN void ASDisplayNodePerformBlockOnEveryYogaChild(ASDisplayNode * _Nullab
// Will walk up the Yoga tree and returns the root node
- (ASDisplayNode *)yogaRoot;


@end

@interface ASDisplayNode (YogaLocking)
/**
* @discussion Attempts(spinning) to lock all node up to root node when yoga is enabled.
* This will lock self when yoga is not enabled;
Expand Down
37 changes: 36 additions & 1 deletion Source/ASDisplayNode+Yoga.mm
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
#import <AsyncDisplayKit/ASDisplayNodeInternal.h>
#import <AsyncDisplayKit/ASLayout.h>
#import <AsyncDisplayKit/ASLayoutElementStylePrivate.h>
#import <AsyncDisplayKit/ASNodeController+Beta.h>

#import <AsyncDisplayKit/ASDisplayNode+LayoutSpec.h>

#define YOGA_LAYOUT_LOGGING 0

#pragma mark - ASDisplayNode+Yoga

@interface ASDisplayNode (YogaInternal)
@interface ASDisplayNode (YogaPrivate)
@property (nonatomic, weak) ASDisplayNode *yogaParent;
- (ASSizeRange)_locked_constrainedSizeForLayoutPass;
@end
Expand Down Expand Up @@ -409,6 +410,40 @@ - (void)calculateLayoutFromYogaRoot:(ASSizeRange)rootConstrainedSize

@end

#pragma mark - ASDisplayNode (YogaLocking)

@implementation ASDisplayNode (YogaLocking)

- (ASLockSet)lockToRootIfNeededForLayout {
ASLockSet lockSet = ASLockSequence(^BOOL(ASAddLockBlock addLock) {
if (!addLock(self)) {
return NO;
}
#if YOGA
if (![self locked_shouldLayoutFromYogaRoot]) {
return YES;
}
if (self.nodeController && !addLock(self.nodeController)) {
return NO;
}
ASDisplayNode *parent = _supernode;
while (parent) {
if (!addLock(parent)) {
return NO;
}
if (parent.nodeController && !addLock(parent.nodeController)) {
return NO;
}
parent = parent->_supernode;
}
#endif
return true;
});
return lockSet;
}

@end

@implementation ASDisplayNode (YogaDebugging)

- (NSString *)yogaTreeDescription {
Expand Down
10 changes: 5 additions & 5 deletions Source/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2842,7 +2842,7 @@ - (void)willEnterHierarchy

if (![self supportsRangeManagedInterfaceState]) {
self.interfaceState = ASInterfaceStateInHierarchy;
} else if (ASCATransactionQueue.sharedQueue.isEnabled) {
} else if (ASCATransactionQueueGet().enabled) {
__instanceLock__.lock();
ASInterfaceState state = _preExitingInterfaceState;
_preExitingInterfaceState = ASInterfaceStateNone;
Expand Down Expand Up @@ -2902,7 +2902,7 @@ - (void)didExitHierarchy
}
};

if (!ASCATransactionQueue.sharedQueue.enabled) {
if (!ASCATransactionQueueGet().enabled) {
dispatch_async(dispatch_get_main_queue(), exitVisibleInterfaceState);
} else {
exitVisibleInterfaceState();
Expand Down Expand Up @@ -2967,13 +2967,13 @@ - (ASInterfaceState)interfaceState

- (void)setInterfaceState:(ASInterfaceState)newState
{
if (!ASCATransactionQueue.sharedQueue.enabled) {
if (!ASCATransactionQueueGet().enabled) {
[self applyPendingInterfaceState:newState];
} else {
MutexLocker l(__instanceLock__);
if (_pendingInterfaceState != newState) {
_pendingInterfaceState = newState;
[[ASCATransactionQueue sharedQueue] enqueue:self];
[ASCATransactionQueueGet() enqueue:self];
}
}
}
Expand All @@ -2999,7 +2999,7 @@ - (void)applyPendingInterfaceState:(ASInterfaceState)newPendingState
MutexLocker l(__instanceLock__);
// newPendingState will not be used when ASCATransactionQueue is enabled
// and use _pendingInterfaceState instead for interfaceState update.
if (!ASCATransactionQueue.sharedQueue.enabled) {
if (!ASCATransactionQueueGet().enabled) {
_pendingInterfaceState = newPendingState;
}
oldState = _interfaceState;
Expand Down
17 changes: 8 additions & 9 deletions Source/ASExperimentalFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ typedef NS_OPTIONS(NSUInteger, ASExperimentalFeatures) {
ASExperimentalInterfaceStateCoalescing = 1 << 2, // exp_interface_state_coalesce
ASExperimentalUnfairLock = 1 << 3, // exp_unfair_lock
ASExperimentalLayerDefaults = 1 << 4, // exp_infer_layer_defaults
ASExperimentalNetworkImageQueue = 1 << 5, // exp_network_image_queue
ASExperimentalCollectionTeardown = 1 << 6, // exp_collection_teardown
ASExperimentalFramesetterCache = 1 << 7, // exp_framesetter_cache
ASExperimentalSkipClearData = 1 << 8, // exp_skip_clear_data
ASExperimentalDidEnterPreloadSkipASMLayout = 1 << 9, // exp_did_enter_preload_skip_asm_layout
ASExperimentalDisableAccessibilityCache = 1 << 10, // exp_disable_a11y_cache
ASExperimentalSkipAccessibilityWait = 1 << 11, // exp_skip_a11y_wait
ASExperimentalNewDefaultCellLayoutMode = 1 << 12, // exp_new_default_cell_layout_mode
ASExperimentalDispatchApply = 1 << 13, // exp_dispatch_apply
ASExperimentalCollectionTeardown = 1 << 5, // exp_collection_teardown
ASExperimentalFramesetterCache = 1 << 6, // exp_framesetter_cache
ASExperimentalSkipClearData = 1 << 7, // exp_skip_clear_data
ASExperimentalDidEnterPreloadSkipASMLayout = 1 << 8, // exp_did_enter_preload_skip_asm_layout
ASExperimentalDisableAccessibilityCache = 1 << 9, // exp_disable_a11y_cache
ASExperimentalSkipAccessibilityWait = 1 << 10, // exp_skip_a11y_wait
ASExperimentalNewDefaultCellLayoutMode = 1 << 11, // exp_new_default_cell_layout_mode
ASExperimentalDispatchApply = 1 << 12, // exp_dispatch_apply
ASExperimentalFeatureAll = 0xFFFFFFFF
};

Expand Down
1 change: 0 additions & 1 deletion Source/ASExperimentalFeatures.mm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
@"exp_interface_state_coalesce",
@"exp_unfair_lock",
@"exp_infer_layer_defaults",
@"exp_network_image_queue",
@"exp_collection_teardown",
@"exp_framesetter_cache",
@"exp_skip_clear_data",
Expand Down
11 changes: 1 addition & 10 deletions Source/ASNetworkImageNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,7 @@ - (void)dealloc

- (dispatch_queue_t)callbackQueue
{
static dispatch_once_t onceToken;
static dispatch_queue_t callbackQueue;
dispatch_once(&onceToken, ^{
if (ASActivateExperimentalFeature(ASExperimentalNetworkImageQueue)) {
callbackQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
} else {
callbackQueue = dispatch_get_main_queue();
}
});
return callbackQueue;
return dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
}

#pragma mark - Public methods -- must lock
Expand Down
22 changes: 15 additions & 7 deletions Source/ASRunLoopQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@ AS_SUBCLASSING_RESTRICTED

@end

AS_SUBCLASSING_RESTRICTED
@interface ASCATransactionQueue : ASAbstractRunLoopQueue

@property (readonly) BOOL isEmpty;

@property (readonly, getter=isEnabled) BOOL enabled;

/**
* The queue to run on main run loop before CATransaction commit.
Expand All @@ -62,13 +57,26 @@ AS_SUBCLASSING_RESTRICTED
* to get last chance of updating/coalesce info like interface state.
* Each node will only be called once per transaction commit to reflect interface change.
*/
@property (class, readonly) ASCATransactionQueue *sharedQueue;
+ (ASCATransactionQueue *)sharedQueue NS_RETURNS_RETAINED;
AS_SUBCLASSING_RESTRICTED
@interface ASCATransactionQueue : ASAbstractRunLoopQueue

@property (readonly) BOOL isEmpty;

@property (readonly, getter=isEnabled) BOOL enabled;

- (void)enqueue:(id<ASCATransactionQueueObserving>)object;

@end

NS_INLINE ASCATransactionQueue *ASCATransactionQueueGet(void) {
static ASCATransactionQueue *q;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
q = [[ASCATransactionQueue alloc] init];
});
return q;
}

@interface ASDeallocQueue : NSObject

@property (class, readonly) ASDeallocQueue *sharedDeallocationQueue;
Expand Down
Loading

0 comments on commit b2bcd0f

Please sign in to comment.