You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by cx...@apache.org on 2018/06/21 08:22:56 UTC

[8/8] incubator-weex git commit: [WEEX-468][iOS] Try to fix Fixed component related crash.

[WEEX-468][iOS] Try to fix Fixed component related crash.


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/732f7eef
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/732f7eef
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/732f7eef

Branch: refs/heads/release
Commit: 732f7eef609f36553accb9e8df8aef0008961b1d
Parents: 4635699
Author: Xiaomin <ca...@yahoo.com>
Authored: Wed Jun 20 19:47:45 2018 +0800
Committer: Adam Feng <cx...@gmail.com>
Committed: Thu Jun 21 16:22:45 2018 +0800

----------------------------------------------------------------------
 ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.mm | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/732f7eef/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.mm
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.mm b/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.mm
index da05dd4..67d1c7a 100644
--- a/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.mm
+++ b/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.mm
@@ -64,6 +64,8 @@ static NSThread *WXComponentThread;
     NSMutableArray *_fixedComponents;
     WeexCore::WXCoreLayoutNode* _rootFlexCSSNode;
     CADisplayLink *_displayLink;
+    pthread_mutex_t _propertyMutex;
+    pthread_mutexattr_t _propertMutexAttr;
 }
 
 + (instancetype)sharedManager
@@ -85,6 +87,9 @@ static NSThread *WXComponentThread;
         _fixedComponents = [NSMutableArray wx_mutableArrayUsingWeakReferences];
         _uiTaskQueue = [NSMutableArray array];
         _isValid = YES;
+        pthread_mutexattr_init(&_propertMutexAttr);
+        pthread_mutexattr_settype(&_propertMutexAttr, PTHREAD_MUTEX_RECURSIVE);
+        pthread_mutex_init(&_propertyMutex, &_propertMutexAttr);
         [self _startDisplayLink];
     }
     
@@ -102,6 +107,8 @@ static NSThread *WXComponentThread;
         _rootFlexCSSNode=nullptr;
     }
     [NSMutableArray wx_releaseArray:_fixedComponents];
+    pthread_mutex_destroy(&_propertyMutex);
+    pthread_mutexattr_destroy(&_propertMutexAttr);
 }
 
 #pragma mark Thread Management
@@ -979,13 +986,17 @@ static NSThread *WXComponentThread;
 
 - (void)addFixedComponent:(WXComponent *)fixComponent
 {
+    pthread_mutex_lock(&_propertyMutex);
     [_fixedComponents addObject:fixComponent];
-        _rootFlexCSSNode->addChildAt(fixComponent.flexCssNode, (uint32_t)([_fixedComponents count]-1));
+    _rootFlexCSSNode->addChildAt(fixComponent.flexCssNode, (uint32_t)([_fixedComponents count]-1));
+    pthread_mutex_unlock(&_propertyMutex);
 }
 
 - (void)removeFixedComponent:(WXComponent *)fixComponent
 {
+    pthread_mutex_lock(&_propertyMutex);
     [_fixedComponents removeObject:fixComponent];
+    pthread_mutex_unlock(&_propertyMutex);
     [self removeFixFlexNode:fixComponent->_flexCssNode];
 }