Stricter locking assertions (#1024)

- Rename `ASDisplayNodeAssertLockUnownedByCurrentThread` to `ASAssertUnlocked`, and `ASDisplayNodeAssertLockOwnedByCurrentThread` to `ASAssertLocked` -> shorter and hopefully easier to distinguish between the two.
- Add assertions to `_locked_` and `_u_` (i.e "unlocked") methods.
- Turn `CHECK_LOCKING_SAFETY` flag on by default. After #1022 and #1023, we're in a good shape to actually enforce locked/unlocked requirements of internal methods. Our test suite passed, and we'll test more at Pinterest after the sync this week.
- Fix ASVideoNode to avoid calling `play` while holding the lock. That method inserts a subnode and must be called lock free.
- Simplify `_loaded(node)` to only nil-check `_layer` because regardless of whether the node is view or layer backed, the layer should always be set if loaded. Use it throughout.
- Other minor changes.
This commit is contained in:
Huy Nguyen
2018-07-13 14:58:16 -07:00
committed by GitHub
parent 8cd123b0de
commit 0dc97fbb2f
14 changed files with 180 additions and 93 deletions

View File

@@ -20,6 +20,7 @@
#import <AsyncDisplayKit/ASAvailability.h>
#import <AsyncDisplayKit/ASBasicImageDownloader.h>
#import <AsyncDisplayKit/ASDisplayNodeExtras.h>
#import <AsyncDisplayKit/ASDisplayNodeInternal.h>
#import <AsyncDisplayKit/ASDisplayNode+FrameworkPrivate.h>
#import <AsyncDisplayKit/ASDisplayNode+Subclasses.h>
#import <AsyncDisplayKit/ASEqualityHelpers.h>
@@ -149,6 +150,8 @@
- (void)_locked_setImage:(UIImage *)image
{
ASAssertLocked(__instanceLock__);
BOOL imageWasSetExternally = (image != nil);
BOOL shouldCancelAndClear = imageWasSetExternally && (imageWasSetExternally != _imageWasSetExternally);
_imageWasSetExternally = imageWasSetExternally;
@@ -175,6 +178,7 @@
- (void)_locked__setImage:(UIImage *)image
{
ASAssertLocked(__instanceLock__);
[super _locked_setImage:image];
}
@@ -508,6 +512,8 @@
- (void)_locked_cancelDownloadAndClearImageWithResumePossibility:(BOOL)storeResume
{
ASAssertLocked(__instanceLock__);
[self _locked_cancelImageDownloadWithResumePossibility:storeResume];
[self _locked_setAnimatedImage:nil];
@@ -532,6 +538,8 @@
- (void)_locked_cancelImageDownloadWithResumePossibility:(BOOL)storeResume
{
ASAssertLocked(__instanceLock__);
if (!_downloadIdentifier) {
return;
}