Fix some threading issue.
This commit is contained in:
1 parent
d34a2876db
commit
9224a6e0db
4 files changed
+30
-16
No files matched your search
@@ -56,4 +56,3 @@ extern NSString *SBQueueCancelledNotification;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
+25
-11
@@ -15,21 +15,21 @@ NSString *SBQueueFailedNotification = @"SBQueueFailedNotification";
|
||||
NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
|
||||
|
||||
@interface SBQueue ()
|
||||
{
|
||||
IOPMAssertionID _assertionID;
|
||||
IOReturn _io_success;
|
||||
}
|
||||
|
||||
@property (atomic) SBQueueStatus status;
|
||||
|
||||
@property (nonatomic, copy) NSURL *URL;
|
||||
@property (nonatomic) NSMutableArray *items;
|
||||
|
||||
@property (nonatomic) NSUInteger currentIndex;
|
||||
@property (atomic) SBQueueItem *currentItem;
|
||||
@property (atomic) NSUInteger currentIndex;
|
||||
@property (atomic) BOOL cancelled;
|
||||
|
||||
@property (nonatomic) IOPMAssertionID assertionID;
|
||||
@property (nonatomic) IOReturn io_success;
|
||||
|
||||
@property (nonatomic) dispatch_queue_t workQueue;
|
||||
@property (nonatomic) dispatch_queue_t saveQueue;
|
||||
|
||||
@end
|
||||
|
||||
@@ -39,12 +39,14 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_workQueue = dispatch_queue_create("org.subler.WorkQueue", NULL);
|
||||
_saveQueue = dispatch_queue_create("org.subler.SaveQueue", NULL);
|
||||
_URL = [queueURL copy];
|
||||
|
||||
if ([[NSFileManager defaultManager] fileExistsAtPath:queueURL.path]) {
|
||||
@try {
|
||||
_items = [NSKeyedUnarchiver unarchiveObjectWithFile:queueURL.path];
|
||||
} @catch (NSException *exception) {
|
||||
}
|
||||
@catch (NSException *exception) {
|
||||
[[NSFileManager defaultManager] removeItemAtURL:queueURL error:nil];
|
||||
_items = nil;
|
||||
}
|
||||
@@ -64,10 +66,13 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
|
||||
}
|
||||
|
||||
- (BOOL)saveQueueToDisk {
|
||||
return [NSKeyedArchiver archiveRootObject:self.items toFile:(self.URL).path];
|
||||
__block BOOL result;
|
||||
dispatch_sync(self.saveQueue, ^{
|
||||
result = [NSKeyedArchiver archiveRootObject:self.items toFile:self.URL.path];
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
- (SBQueueItem *)firstItemInQueue {
|
||||
__block SBQueueItem *firstItem = nil;
|
||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||
@@ -82,6 +87,14 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
|
||||
return firstItem;
|
||||
}
|
||||
|
||||
- (NSUInteger)indexOfCurrentItem {
|
||||
__block NSUInteger index;
|
||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||
index = [self.items indexOfObject:self.currentItem];
|
||||
});
|
||||
return index;
|
||||
}
|
||||
|
||||
#pragma mark - item management
|
||||
|
||||
- (void)addItem:(SBQueueItem *)item {
|
||||
@@ -89,7 +102,7 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
|
||||
}
|
||||
|
||||
- (NSUInteger)count {
|
||||
return (self.items).count;
|
||||
return self.items.count;
|
||||
}
|
||||
|
||||
- (NSUInteger)readyCount {
|
||||
@@ -193,7 +206,7 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
|
||||
break;
|
||||
}
|
||||
|
||||
self.currentIndex = [self.items indexOfObject:self.currentItem];
|
||||
self.currentIndex = [self indexOfCurrentItem];
|
||||
self.currentItem.status = SBQueueItemStatusWorking;
|
||||
self.currentItem.delegate = self;
|
||||
|
||||
@@ -213,7 +226,8 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
|
||||
if (noErr) {
|
||||
self.currentItem.status = SBQueueItemStatusCompleted;
|
||||
completedCount += 1;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
self.currentItem.status = SBQueueItemStatusFailed;
|
||||
failedCount += 1;
|
||||
[self handleSBStatusFailed:outError];
|
||||
|
||||
@@ -325,10 +325,11 @@
|
||||
[self didChangeValueForKey:@"fileURL"];
|
||||
|
||||
if (!self.cancelled) {
|
||||
if ([self.fileURL isEqualTo:self.destURL] && (self.mp4File).hasFileRepresentation) {
|
||||
if ([self.fileURL isEqualTo:self.destURL] && self.mp4File.hasFileRepresentation) {
|
||||
// We have an existing mp4 file, update it
|
||||
noErr = [self.mp4File updateMP4FileWithOptions:self.attributes error:outError];
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// Write the new file to disk
|
||||
noErr = [self.mp4File writeToUrl:self.destURL
|
||||
options:self.attributes
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
archiveVersion = 1;
|
||||
classes = {
|
||||
};
|
||||
objectVersion = 46;
|
||||
objectVersion = 48;
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
@@ -739,7 +739,7 @@
|
||||
};
|
||||
};
|
||||
buildConfigurationList = C05733CB08A9546B00998B17 /* Build configuration list for PBXProject "Subler" */;
|
||||
compatibilityVersion = "Xcode 3.2";
|
||||
compatibilityVersion = "Xcode 8.0";
|
||||
developmentRegion = English;
|
||||
hasScannedForEncodings = 1;
|
||||
knownRegions = (
|
||||
|
||||
Reference in new issue
Block a user