From 3e332fbde5f59a85f518a9a817dfb476ddadd2e1 Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Fri, 23 Mar 2018 12:43:29 +0100 Subject: [PATCH] Fix some deadlocks. --- Classes/SBQueue.h | 2 -- Classes/SBQueue.m | 17 ++++++++--------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/Classes/SBQueue.h b/Classes/SBQueue.h index 8789046..b6c846e 100644 --- a/Classes/SBQueue.h +++ b/Classes/SBQueue.h @@ -15,8 +15,6 @@ typedef NS_ENUM(NSUInteger, SBQueueStatus) { SBQueueStatusUnknown = 0, SBQueueStatusWorking, SBQueueStatusCompleted, - SBQueueStatusFailed, - SBQueueStatusCancelled, }; extern NSString *SBQueueWorkingNotification; diff --git a/Classes/SBQueue.m b/Classes/SBQueue.m index 8681c80..2f52993 100644 --- a/Classes/SBQueue.m +++ b/Classes/SBQueue.m @@ -222,14 +222,15 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification"; * Starts the queue. */ - (void)start { - if (self.status == SBQueueStatusWorking || self.cancelled) { - return; - } else { - self.status = SBQueueStatusWorking; - } + dispatch_sync(self.arrayQueue, ^{ + if (self.status == SBQueueStatusWorking || self.cancelled) { + return; + } else { + self.status = SBQueueStatusWorking; + } + }); dispatch_async(self.workQueue, ^{ - // Enable sleep assertion [self disableSleep]; @@ -287,7 +288,7 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification"; [self handleSBStatusWorking:100 index:self.currentIndex]; } - if (self.status == SBQueueStatusCancelled) { + if (self.cancelled) { break; } } @@ -344,7 +345,6 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification"; * sends SBQueueFailedNotification. */ - (void)handleSBStatusFailed:(NSError *)error { - self.status = SBQueueStatusFailed; [[NSNotificationCenter defaultCenter] postNotificationName:SBQueueFailedNotification object:self userInfo:@{@"Error" : error != nil ? error : [NSNull null]}]; } @@ -353,7 +353,6 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification"; * sends SBQueueCancelledNotification. */ - (void)handleSBStatusCancelled { - self.status = SBQueueStatusCancelled; [[NSNotificationCenter defaultCenter] postNotificationName:SBQueueCancelledNotification object:self]; }