Fix some deadlocks.

This commit is contained in:
Damiano Galassi committed 2018-03-23 12:43:29 +01:00
1 parent bc3d17c9f9
commit 3e332fbde5
2 files changed
+8 -11

No files matched your search

-2
View File
@@ -15,8 +15,6 @@ typedef NS_ENUM(NSUInteger, SBQueueStatus) {
SBQueueStatusUnknown = 0, SBQueueStatusUnknown = 0,
SBQueueStatusWorking, SBQueueStatusWorking,
SBQueueStatusCompleted, SBQueueStatusCompleted,
SBQueueStatusFailed,
SBQueueStatusCancelled,
}; };
extern NSString *SBQueueWorkingNotification; extern NSString *SBQueueWorkingNotification;
+8 -9
View File
@@ -222,14 +222,15 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
* Starts the queue. * Starts the queue.
*/ */
- (void)start { - (void)start {
if (self.status == SBQueueStatusWorking || self.cancelled) { dispatch_sync(self.arrayQueue, ^{
return; if (self.status == SBQueueStatusWorking || self.cancelled) {
} else { return;
self.status = SBQueueStatusWorking; } else {
} self.status = SBQueueStatusWorking;
}
});
dispatch_async(self.workQueue, ^{ dispatch_async(self.workQueue, ^{
// Enable sleep assertion // Enable sleep assertion
[self disableSleep]; [self disableSleep];
@@ -287,7 +288,7 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
[self handleSBStatusWorking:100 index:self.currentIndex]; [self handleSBStatusWorking:100 index:self.currentIndex];
} }
if (self.status == SBQueueStatusCancelled) { if (self.cancelled) {
break; break;
} }
} }
@@ -344,7 +345,6 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
* sends SBQueueFailedNotification. * sends SBQueueFailedNotification.
*/ */
- (void)handleSBStatusFailed:(NSError *)error { - (void)handleSBStatusFailed:(NSError *)error {
self.status = SBQueueStatusFailed;
[[NSNotificationCenter defaultCenter] postNotificationName:SBQueueFailedNotification object:self userInfo:@{@"Error" : error != nil ? error : [NSNull null]}]; [[NSNotificationCenter defaultCenter] postNotificationName:SBQueueFailedNotification object:self userInfo:@{@"Error" : error != nil ? error : [NSNull null]}];
} }
@@ -353,7 +353,6 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
* sends SBQueueCancelledNotification. * sends SBQueueCancelledNotification.
*/ */
- (void)handleSBStatusCancelled { - (void)handleSBStatusCancelled {
self.status = SBQueueStatusCancelled;
[[NSNotificationCenter defaultCenter] postNotificationName:SBQueueCancelledNotification object:self]; [[NSNotificationCenter defaultCenter] postNotificationName:SBQueueCancelledNotification object:self];
} }