Fabric: The second attempt to fix a thread-safety issue in RCTNativeAnimatedModule

Summary:
Previously we tried to fix that with RCTUnsafeExecuteOnUIManagerQueueSync but that caused a deadlock (yeah, it's actually unsafe).
Besides that, I tried to solve that with introducing a mutex that covers access to `_operations` and `_preOperations` but failed miserably. It solved threading issue but that didn't fix data-races and inconsistency of the collections.

Reviewed By: sahrens

Differential Revision: D15587564

fbshipit-source-id: d1953036b09354d1663a9b191440f8b4a4e6be9d
This commit is contained in:
Valentin Shergin
2019-06-01 20:07:50 -07:00
committed by Facebook Github Bot
parent 5a8cdb4bb7
commit a2913d33a6
@@ -232,27 +232,31 @@ RCT_EXPORT_METHOD(removeAnimatedEventFromView:(nonnull NSNumber *)viewTag
- (void)willMountComponentsWithRootTag:(NSInteger)rootTag
{
RCTAssertMainQueue();
__block NSArray<AnimatedOperation> *preOperations;
RCTUnsafeExecuteOnUIManagerQueueSync(^{
preOperations = self->_preOperations;
RCTExecuteOnUIManagerQueue(^{
NSArray<AnimatedOperation> *preOperations = self->_preOperations;
self->_preOperations = [NSMutableArray new];
RCTExecuteOnMainQueue(^{
for (AnimatedOperation preOperation in preOperations) {
preOperation(self->_nodesManager);
}
});
});
for (AnimatedOperation operation in preOperations) {
operation(self->_nodesManager);
}
}
- (void)didMountComponentsWithRootTag:(NSInteger)rootTag
{
RCTAssertMainQueue();
__block NSArray<AnimatedOperation> *operations;
RCTUnsafeExecuteOnUIManagerQueueSync(^{
operations = self->_operations;
RCTExecuteOnUIManagerQueue(^{
NSArray<AnimatedOperation> *operations = self->_operations;
self->_operations = [NSMutableArray new];
RCTExecuteOnMainQueue(^{
for (AnimatedOperation operation in operations) {
operation(self->_nodesManager);
}
});
});
for (AnimatedOperation operation in operations) {
operation(self->_nodesManager);
}
}
#pragma mark - RCTUIManagerObserver