Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
[iOS] Restore recursive lock and add some comments. (#1726)
Browse files Browse the repository at this point in the history
  • Loading branch information
wqyfavor authored and cxfeng1 committed Nov 9, 2018
1 parent f1117e5 commit bd663a8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ios/sdk/WeexSDK/Sources/Utility/WXThreadSafeMutableArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
*/
@interface WXThreadSafeMutableArray : NSMutableArray

/* WXThreadSafeMutableArray inherites from NSMutableArray for backward capability.
Keep in mind that only the following methods are thread safe guaranteed.
And MUST not use other methods provideded by NSMutableArray. */

- (instancetype)init;
- (instancetype)initWithCapacity:(NSUInteger)numItems;
- (instancetype)initWithArray:(NSArray *)array;
Expand Down
2 changes: 1 addition & 1 deletion ios/sdk/WeexSDK/Sources/Utility/WXThreadSafeMutableArray.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ - (instancetype)initCommon
self = [super init];
if (self) {
pthread_mutexattr_init(&(_safeThreadArrayMutexAttr));
pthread_mutexattr_settype(&(_safeThreadArrayMutexAttr), PTHREAD_MUTEX_DEFAULT);
pthread_mutexattr_settype(&(_safeThreadArrayMutexAttr), PTHREAD_MUTEX_RECURSIVE); // must use recursive lock
pthread_mutex_init(&(_safeThreadArrayMutex), &(_safeThreadArrayMutexAttr));
}
return self;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
*/
@interface WXThreadSafeMutableDictionary<KeyType, ObjectType> : NSMutableDictionary

/* WXThreadSafeMutableDictionary inherites from NSMutableDictionary for backward capability.
Keep in mind that only the following methods are thread safe guaranteed.
And MUST not use other methods provideded by NSMutableDictionary. */

- (instancetype)init;
- (instancetype)initWithCapacity:(NSUInteger)numItems;
- (instancetype)initWithDictionary:(NSDictionary *)dictionary;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ - (instancetype)initCommon
self = [super init];
if (self) {
pthread_mutexattr_init(&(_safeThreadDictionaryMutexAttr));
pthread_mutexattr_settype(&(_safeThreadDictionaryMutexAttr), PTHREAD_MUTEX_DEFAULT);
pthread_mutexattr_settype(&(_safeThreadDictionaryMutexAttr), PTHREAD_MUTEX_RECURSIVE); // must use recursive lock
pthread_mutex_init(&(_safeThreadDictionaryMutex), &(_safeThreadDictionaryMutexAttr));
}
return self;
Expand Down

0 comments on commit bd663a8

Please sign in to comment.