-
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
Allow to add interface state delegate in background. #1090
Allow to add interface state delegate in background. #1090
Conversation
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 don't think this is enough. Other places that use _interfaceStateDelegates
always assert main thread and don't acquire the lock so they need to be updated as well.
Thanks, the only other place seems to be remove. The delegate call outs need to be on main. |
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.
For other places that are on main, we still need to acquire the lock before accessing this property, otherwise we will run into race conditions.
Source/ASDisplayNode.mm
Outdated
for (id <ASInterfaceStateDelegate> delegate in _interfaceStateDelegates) { | ||
if ([delegate respondsToSelector:@selector(nodeDidLoad)]) { | ||
[delegate nodeDidLoad]; | ||
@synchronized (_interfaceStateDelegates) { |
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.
Please use __instanceLock__
.
In some methods, like this one, the lock is acquired earlier (i.e a few lines above). You can take advantage of that by storing the delegates in a local variable while the lock is being held, then use it a bit later on.
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.
delegates calling like didEnterVisibleState is requring ASAssertUnlocked(instanceLock);
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.
Ah yeah, that just means that method requires to be called without the lock, but within the method it can acquire the lock itself.
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.
instanceLock.lock();
NSHashTable * delegates = [_interfaceStateDelegates copy];
instanceLock.unlock();
...
ASAssertUnlocked(instanceLock);
...
for (id delegate in delegates) {
if ([delegate respondsToSelector:@selector(nodeDidLoad)]) {
[delegate nodeDidLoad];
}
}
Will something like this work
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.
Yes.
🚫 CI failed with log |
Source/ASDisplayNode.mm
Outdated
@@ -460,6 +460,16 @@ - (void)dealloc | |||
|
|||
#pragma mark - Loading | |||
|
|||
#define ASDisplayNodeCallInterfaceStateDelegates(method, __lock) \ | |||
__lock.lock(); \ | |||
NSHashTable *delegates = _interfaceStateDelegates; \ |
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.
Don't we need to copy the hash table? Same for a couple of other places.
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.
Good Point. Thanks.
Source/ASDisplayNode.mm
Outdated
@@ -460,6 +460,16 @@ - (void)dealloc | |||
|
|||
#pragma mark - Loading | |||
|
|||
#define ASDisplayNodeCallInterfaceStateDelegates(method, __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.
Since __lock
is always the same (i.e __instanceLock__
), should we just remove the param entirely?
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.
Done.
One last thing, please update CHANGELOG. |
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.
LGTM 👍
* fix SIMULATE_WEB_RESPONSE not imported TextureGroup#449 * Fix to make rangeMode update in right time * remove uncessary assert * Allow to add interface state delegate in background threads. * Allow to add interface state delegate in background threads. * lock around _interfaceStateDelegates * lock _interfaceStateDelegates to local variable * Fix comments * remove extra spaces
No description provided.