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

Allow to add interface state delegate in background. #1090

Conversation

wsdwsd0829
Copy link
Contributor

No description provided.

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.

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.

@wsdwsd0829
Copy link
Contributor Author

Thanks, the only other place seems to be remove. The delegate call outs need to be on main.

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.

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.

for (id <ASInterfaceStateDelegate> delegate in _interfaceStateDelegates) {
if ([delegate respondsToSelector:@selector(nodeDidLoad)]) {
[delegate nodeDidLoad];
@synchronized (_interfaceStateDelegates) {
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

Choose a reason for hiding this comment

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

Yes.

@ghost
Copy link

ghost commented Aug 30, 2018

🚫 CI failed with log

@@ -460,6 +460,16 @@ - (void)dealloc

#pragma mark - Loading

#define ASDisplayNodeCallInterfaceStateDelegates(method, __lock) \
__lock.lock(); \
NSHashTable *delegates = _interfaceStateDelegates; \
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good Point. Thanks.

@@ -460,6 +460,16 @@ - (void)dealloc

#pragma mark - Loading

#define ASDisplayNodeCallInterfaceStateDelegates(method, __lock) \
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@nguyenhuy
Copy link
Member

One last thing, please update CHANGELOG.

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.

LGTM 👍

@nguyenhuy nguyenhuy merged commit eba4e29 into TextureGroup:master Aug 31, 2018
mikezucc pushed a commit to mikezucc/Texture that referenced this pull request Oct 2, 2018
* 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
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

3 participants