Stricter locking assertions#1024
Conversation
There was a problem hiding this comment.
Apply the same fix in #1022 here just to be safe, i.e if _u_setNeedsLayoutFromAbove causes an assertion, it'll be correctly shown.
There was a problem hiding this comment.
While having the lock, call the _locked_ method.
There was a problem hiding this comment.
Cache these properties to improve readability of the following lines
#notAPerfOptimization
There was a problem hiding this comment.
Easier to just call the "unlocked" variant.
There was a problem hiding this comment.
Can't call the _locked_ method here
There was a problem hiding this comment.
As mentions in the description, play shouldn't be called with the lock.
There was a problem hiding this comment.
Is it worth adding a comment in code?
|
🚫 CI failed with log |
Adlai-Holler
left a comment
There was a problem hiding this comment.
If we're renaming the macro, how about ASAssertLocked and ASAssertUnlocked? Over time I'd like to move away from ASDisplayNode as a prefix, since the framework now encompasses so much more.
|
Uhh, I like that. Will update! |
4a0ebd2 to
465be36
Compare
- Rename `ASDisplayNodeAssertLockUnownedByCurrentThread` to `ASDisplayNodeAssertLockNotHeld`, and `ASDisplayNodeAssertLockOwnedByCurrentThread` to `ASDisplayNodeAssertLockHeld` -> 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 TextureGroup#1022 and TextureGroup#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. - Other minor changes.
465be36 to
c037799
Compare
| ASAssertLocked(__instanceLock__); | ||
|
|
||
| CGSize boundsSizeForLayout = ASCeilSizeValues(self.threadSafeBounds.size); | ||
| std::shared_ptr<ASDisplayNodeLayout> pendingLayout = _pendingDisplayNodeLayout; |
There was a problem hiding this comment.
Do you mind adding a comment explaining the shared_ptr's here?
|
|
||
| - (BOOL)_isNodeLoaded | ||
| { | ||
| return (_view != nil || (_layer != nil && _flags.layerBacked)); |
There was a problem hiding this comment.
Does this need to be updated with a lock?
There was a problem hiding this comment.
This method is called unlocked, and the client is responsible for its safety. Renamed to -_unsafe_unlocked_isNodeLoaded to reflect that.
| } | ||
|
|
||
| /// Called without the lock. Client is responsible for locking safety. | ||
| - (BOOL)_unsafe_unlocked_isNodeLoaded |
There was a problem hiding this comment.
Can we simplify all of this by just using _layer != nil inline when we want a fast loaded check?
| ASDISPLAYNODE_INLINE AS_WARN_UNUSED_RESULT BOOL _ASIsNodeLoaded(ASDisplayNode *node) | ||
| { | ||
| return (_view != nil || (_layer != nil && _flags.layerBacked)); | ||
| return (node->_view != nil || (node->_layer != nil && node->_flags.layerBacked)); |
There was a problem hiding this comment.
What if we get rid of this function and just put _layer != nil inside the places where we need it?
…huy/Texture into HN-Stricter-Locking-Safety-Checks
…layer backed, the layer should always be set if loaded
- 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 TextureGroup#1022 and TextureGroup#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.
ASDisplayNodeAssertLockUnownedByCurrentThreadtoASAssertUnlocked, andASDisplayNodeAssertLockOwnedByCurrentThreadtoASAssertLocked-> shorter and hopefully easier to distinguish between the two._locked_and_u_(i.e "unlocked") methods.CHECK_LOCKING_SAFETYon by default. After Fix misleading/scary stack trace shown when an assertion occurs during node measurement #1022 and Make sure -_completePendingLayoutTransition is called without the node's instance lock #trivial #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.playwhile holding the lock. That method inserts a subnode and must be called lock free.