Skip to content
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

Merged
merged 2 commits into from
Jul 20, 2018
Merged

Conversation

maicki
Copy link
Contributor

@maicki maicki commented Jul 19, 2018

In ASVideoPlayerNode we are currently adding and removing subnodes with lock held. That's not allowed.

Fixes #1040

@maicki maicki requested a review from nguyenhuy July 19, 2018 16:26
@ghost
Copy link

ghost commented Jul 19, 2018

🚫 CI failed with log

@ghost
Copy link

ghost commented Jul 19, 2018

🚫 CI failed with log

@@ -644,9 +671,11 @@ - (void)showSpinner
}];

_spinnerNode.style.preferredSize = CGSizeMake(44.0, 44.0);

[self addSubnode:_spinnerNode];
Copy link
Contributor Author

@maicki maicki Jul 19, 2018

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.

@@ -658,7 +687,10 @@ - (void)removeSpinner
if (!_spinnerNode) {
return;
}
[_spinnerNode removeFromSupernode];
{
Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Member

@nguyenhuy nguyenhuy left a 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];
Copy link
Member

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];
}
}
Copy link
Member

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.

Copy link
Member

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.

}

[self cleanCachedControls];
[self __locked_cleanCachedControls];
Copy link
Member

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.

}

- (void)cleanCachedControls
- (void)__locked_cleanCachedControls
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ha!

Copy link
Member

@nguyenhuy nguyenhuy Jul 20, 2018

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)?

@@ -658,7 +687,10 @@ - (void)removeSpinner
if (!_spinnerNode) {
return;
}
[_spinnerNode removeFromSupernode];
{
Copy link
Member

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];
}
}
Copy link
Member

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.

@maicki maicki merged commit d9d5b12 into master Jul 20, 2018
@nguyenhuy nguyenhuy deleted the MSVideoPlayerNodeLocking branch July 20, 2018 22:43
mikezucc pushed a commit to mikezucc/Texture that referenced this pull request Oct 2, 2018
* Improve locking in ASVideoPlayerNode

* Address comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants