weex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acton...@apache.org
Subject [1/2] incubator-weex git commit: * [ios] add mutex for text attributedString and coreText framesetter
Date Mon, 03 Jul 2017 07:46:20 GMT
Repository: incubator-weex
Updated Branches:
  refs/heads/0.15-dev 22a338ee6 -> 2552f7ff3


* [ios] add mutex for text attributedString and coreText framesetter


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

Branch: refs/heads/0.15-dev
Commit: a82e521a519d4d5377828d55eed951bf6284cf24
Parents: e0704ae
Author: acton393 <zhangxing610321@gmail.com>
Authored: Mon Jul 3 15:15:07 2017 +0800
Committer: acton393 <zhangxing610321@gmail.com>
Committed: Mon Jul 3 15:15:07 2017 +0800

----------------------------------------------------------------------
 ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/a82e521a/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
index 6cbe8e0..a092019 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
@@ -120,6 +120,10 @@ CGFloat WXTextDefaultLineThroughWidth = 1.2;
     BOOL _needsRemoveObserver;
     NSAttributedString * _ctAttributedString;
     CTFramesetterRef _ctframeSetter;
+    
+    pthread_mutex_t _ctFrameSetterMutex;
+    pthread_mutex_t _ctAttributedStringMutex;
+    pthread_mutexattr_t _propertMutexAttr;
 }
 
 + (void)setRenderUsingCoreText:(BOOL)usingCoreText
@@ -143,6 +147,11 @@ CGFloat WXTextDefaultLineThroughWidth = 1.2;
     if (self) {
         // just for coretext and textkit render replacement
         _needsRemoveObserver = NO;
+        pthread_mutexattr_init(&(_propertMutexAttr));
+        pthread_mutexattr_settype(&(_propertMutexAttr), PTHREAD_MUTEX_RECURSIVE);
+        pthread_mutex_init(&(_ctFrameSetterMutex), &(_propertMutexAttr));
+        pthread_mutex_init(&(_ctAttributedStringMutex), &(_propertMutexAttr));
+        
         if ([attributes objectForKey:@"coretext"]) {
             _useCoreTextAttr = [WXConvert NSString:attributes[@"coretext"]];
         } else {
@@ -181,6 +190,9 @@ CGFloat WXTextDefaultLineThroughWidth = 1.2;
         CFRelease(_ctframeSetter);
         _ctframeSetter = NULL;
     }
+    pthread_mutex_destroy(&_ctAttributedStringMutex);
+    pthread_mutex_destroy(&_ctFrameSetterMutex);
+    pthread_mutexattr_destroy(&_propertMutexAttr);
 }
 
 #define WX_STYLE_FILL_TEXT(key, prop, type, needLayout)\
@@ -348,17 +360,21 @@ do {\
 
 - (NSAttributedString *)ctAttributedString
 {
+    pthread_mutex_lock(&(_ctAttributedStringMutex));
     if (!_ctAttributedString) {
         _ctAttributedString = [[self buildCTAttributeString] copy];
     }
+    pthread_mutex_unlock(&(_ctAttributedStringMutex));
     return [_ctAttributedString copy];
 }
 
 - (CTFramesetterRef)ctFramesetterRef
 {
+    pthread_mutex_lock(&(_ctFrameSetterMutex));
     if (NULL == _ctframeSetter) {
         _ctframeSetter = CTFramesetterCreateWithAttributedString((CFTypeRef)[self ctAttributedString]);
     }
+    pthread_mutex_unlock(&(_ctFrameSetterMutex));
     return _ctframeSetter;
 }
 


Mime
View raw message