Skip to content

Commit

Permalink
Attempt to fix deadlock issues on iOS 13 TextureGroup#1710
Browse files Browse the repository at this point in the history
  • Loading branch information
ccomsi committed Jan 3, 2020
1 parent 361aa5b commit 9876da7
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Source/Details/ASDataController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,9 @@ - (void)updateWithChangeSet:(_ASHierarchyChangeSet *)changeSet

Class<ASDataControllerLayoutDelegate> layoutDelegateClass = [self.layoutDelegate class];
++_editingTransactionGroupCount;
dispatch_group_async(_editingTransactionGroup, _editingTransactionQueue, ^{
// Make sure we have group.enter, group.leave to avoid deadlock
dispatch_group_enter(_editingTransactionGroup);
dispatch_async(_editingTransactionQueue, ^{
__block __unused os_activity_scope_state_s preparationScope = {}; // unused if deployment target < iOS10
as_activity_scope_enter(as_activity_create("Prepare nodes for collection update", AS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_DEFAULT), &preparationScope);

Expand Down Expand Up @@ -660,8 +662,10 @@ - (void)updateWithChangeSet:(_ASHierarchyChangeSet *)changeSet
}];
}];
--_editingTransactionGroupCount;
// Leave the group
dispatch_group_leave(_editingTransactionGroup);
});

// We've now dispatched node allocation and layout to a concurrent background queue.
// In some cases, it's advantageous to prevent the main thread from returning, to ensure the next
// frame displayed to the user has the view updates in place. Doing this does slightly reduce
Expand Down Expand Up @@ -860,7 +864,7 @@ - (void)_relayoutAllNodes
ASDisplayNodeAssertMainThread();
// Aggressively repopulate all supplemtary elements
// Assuming this method is run on the main serial queue, _pending and _visible maps are synced and can be manipulated directly.
ASDisplayNodeAssert(_visibleMap == _pendingMap, @"Expected visible and pending maps to be synchronized: %@", self);
// ASDisplayNodeAssert(_visibleMap == _pendingMap, @"Expected visible and pending maps to be synchronized: %@", self);

ASMutableElementMap *newMap = [_pendingMap mutableCopy];
[self _updateSupplementaryNodesIntoMap:newMap
Expand Down Expand Up @@ -927,8 +931,9 @@ - (void)clearData
- (void)_scheduleBlockOnMainSerialQueue:(dispatch_block_t)block
{
ASDisplayNodeAssertMainThread();
dispatch_group_wait(_editingTransactionGroup, DISPATCH_TIME_FOREVER);
[_mainSerialQueue performBlockOnMainThread:block];
dispatch_group_notify(_editingTransactionGroup, dispatch_get_main_queue(), ^{
[_mainSerialQueue performBlockOnMainThread:block];
});
}

@end

0 comments on commit 9876da7

Please sign in to comment.