Skip to content

Commit 6bbe4cb

Browse files
authored
Fix deadlock in iOS 9.3. (#770)
1 parent c8b0bb7 commit 6bbe4cb

File tree

1 file changed

+12
-24
lines changed

1 file changed

+12
-24
lines changed

Branch-SDK/Branch-SDK/BNCPreferenceHelper.m

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ @interface BNCPreferenceHelper () {
5757
@property (strong, nonatomic) NSMutableDictionary *creditsDictionary;
5858
@property (strong, nonatomic) NSMutableDictionary *requestMetadataDictionary;
5959
@property (strong, nonatomic) NSMutableDictionary *instrumentationDictionary;
60-
6160
@end
6261

6362
@implementation BNCPreferenceHelper
@@ -100,14 +99,16 @@ + (BNCPreferenceHelper *)preferenceHelper {
10099
}
101100

102101
- (id)init {
103-
if ((self = [super init])) {
104-
_timeout = DEFAULT_TIMEOUT;
105-
_retryCount = DEFAULT_RETRY_COUNT;
106-
_retryInterval = DEFAULT_RETRY_INTERVAL;
107-
108-
_isDebug = NO;
109-
}
110-
102+
self = [super init];
103+
if (!self) return self;
104+
105+
_timeout = DEFAULT_TIMEOUT;
106+
_retryCount = DEFAULT_RETRY_COUNT;
107+
_retryInterval = DEFAULT_RETRY_INTERVAL;
108+
_isDebug = NO;
109+
_persistPrefsQueue = [[NSOperationQueue alloc] init];
110+
_persistPrefsQueue.maxConcurrentOperationCount = 1;
111+
111112
return self;
112113
}
113114

@@ -122,21 +123,8 @@ + (BNCPreferenceHelper *)getInstance {
122123
return preferenceHelper;
123124
}
124125

125-
- (NSOperationQueue *)persistPrefsQueue {
126-
@synchronized (self) {
127-
if (_persistPrefsQueue)
128-
return _persistPrefsQueue;
129-
_persistPrefsQueue = [[NSOperationQueue alloc] init];
130-
_persistPrefsQueue.maxConcurrentOperationCount = 1;
131-
return _persistPrefsQueue;
132-
}
133-
}
134-
135126
- (void) synchronize {
136-
@synchronized(self) {
137-
// Flushes preference queue to persistence.
138-
[_persistPrefsQueue waitUntilAllOperationsAreFinished];
139-
}
127+
[_persistPrefsQueue waitUntilAllOperationsAreFinished];
140128
}
141129

142130
- (void) dealloc {
@@ -715,7 +703,7 @@ - (void)persistPrefsToDisk {
715703
BNCLogWarning(@"Failed to persist preferences: %@.", error);
716704
}
717705
}];
718-
[self.persistPrefsQueue addOperation:newPersistOp];
706+
[_persistPrefsQueue addOperation:newPersistOp];
719707
}
720708
}
721709

0 commit comments

Comments
 (0)