-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Improve locking situation in ASVideoPlayerNode #1042
Conversation
🚫 CI failed with log |
cefbf21
to
50f37b1
Compare
🚫 CI failed with log |
Source/ASVideoPlayerNode.mm
Outdated
@@ -644,9 +671,11 @@ - (void)showSpinner | |||
}]; | |||
|
|||
_spinnerNode.style.preferredSize = CGSizeMake(44.0, 44.0); | |||
|
|||
[self addSubnode:_spinnerNode]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spinner can be removed and added on different threads we may should grab the _spinnerNode
before unlocking and adding it.
Source/ASVideoPlayerNode.mm
Outdated
@@ -658,7 +687,10 @@ - (void)removeSpinner | |||
if (!_spinnerNode) { | |||
return; | |||
} | |||
[_spinnerNode removeFromSupernode]; | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may should grab the _spinnerNode
here before unlocking
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do this at the end so we don't need to re-acquire the lock.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last thing: Let's tighten up the locking requirements by adding ASAssertUnlocked
at the beginning of - -createControls
and -removeControls
, as well as ASAssertLocked
at the beginning of _locked_
methods.
@@ -284,15 +282,23 @@ - (void)createControls | |||
|
|||
if (_delegateFlags.delegateCustomControls && _delegateFlags.delegateLayoutSpecForControls) { | |||
NSDictionary *customControls = [_delegate videoPlayerNodeCustomControls:self]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general we should avoid calling delegates with the lock held. May not worth address in this PR though.
for (var subnode : subnodes) { | ||
[self addSubnode:subnode]; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can avoid a pair of lock and unlock calls if we add subnodes outside of the outmost lock scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Talked to @maicki offline. Let's leave this as is since my suggested approach is a bit more complicated and in case of early return(s), the vector will not be used.
Source/ASVideoPlayerNode.mm
Outdated
} | ||
|
||
[self cleanCachedControls]; | ||
[self __locked_cleanCachedControls]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's safe to do this before calling removeFromSupernode
on cached controls? If yes we can avoid the unlock scope.
Source/ASVideoPlayerNode.mm
Outdated
} | ||
|
||
- (void)cleanCachedControls | ||
- (void)__locked_cleanCachedControls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ha!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, should we use 1 underscore at the beginning of this method's name (i.e - (void)_locked_cleanCachedControls
)?
Source/ASVideoPlayerNode.mm
Outdated
@@ -658,7 +687,10 @@ - (void)removeSpinner | |||
if (!_spinnerNode) { | |||
return; | |||
} | |||
[_spinnerNode removeFromSupernode]; | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do this at the end so we don't need to re-acquire the lock.
for (var subnode : subnodes) { | ||
[self addSubnode:subnode]; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Talked to @maicki offline. Let's leave this as is since my suggested approach is a bit more complicated and in case of early return(s), the vector will not be used.
* Improve locking in ASVideoPlayerNode * Address comments
In ASVideoPlayerNode we are currently adding and removing subnodes with lock held. That's not allowed.
Fixes #1040