Fix a race condition.
This commit is contained in:
1 file changed
+47
-21
+47
-21
@@ -19,17 +19,22 @@
|
|||||||
|
|
||||||
@interface SBQueueItem ()
|
@interface SBQueueItem ()
|
||||||
|
|
||||||
@property (nonatomic, readonly) NSString *uniqueID;
|
@property (nonatomic) NSString *uniqueID;
|
||||||
|
|
||||||
@property (nonatomic, readonly) NSMutableArray<id<SBQueueActionProtocol>> *actionsInternal;
|
@property (nonatomic) NSMutableArray<id<SBQueueActionProtocol>> *actionsInternal;
|
||||||
@property (nonatomic, readwrite) NSString *localizedWorkingDescription;
|
@property (nonatomic) NSString *localizedWorkingDescription;
|
||||||
|
|
||||||
@property (nonatomic, readwrite, nullable) MP42File *mp4File;
|
@property (nonatomic, nullable) MP42File *mp4File;
|
||||||
@property (atomic, readwrite) BOOL cancelled;
|
|
||||||
|
@property (nonatomic) dispatch_queue_t queue;
|
||||||
|
@property (nonatomic) _Atomic int32_t cancelled;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation SBQueueItem
|
@implementation SBQueueItem {
|
||||||
|
SBQueueItemStatus _status;
|
||||||
|
NSURL *_fileURL;
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark Initializers
|
#pragma mark Initializers
|
||||||
|
|
||||||
@@ -39,6 +44,7 @@
|
|||||||
_uniqueID = [[NSUUID UUID] UUIDString];
|
_uniqueID = [[NSUUID UUID] UUIDString];
|
||||||
_actionsInternal = [[NSMutableArray alloc] init];
|
_actionsInternal = [[NSMutableArray alloc] init];
|
||||||
_status = SBQueueItemStatusReady;
|
_status = SBQueueItemStatusReady;
|
||||||
|
_queue = dispatch_queue_create("org.subler.itemQueue", DISPATCH_QUEUE_SERIAL);
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@@ -57,9 +63,9 @@
|
|||||||
attributes[MP4264BitData] = @YES;
|
attributes[MP4264BitData] = @YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"chaptersPreviewTrack"] boolValue]) {
|
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"chaptersPreviewTrack"]) {
|
||||||
attributes[MP42GenerateChaptersPreviewTrack] = @YES;
|
attributes[MP42GenerateChaptersPreviewTrack] = @YES;
|
||||||
attributes[MP42ChaptersPreviewPosition] = [NSNumber numberWithFloat:[[NSUserDefaults standardUserDefaults] floatForKey:@"SBChaptersPreviewPosition"]];
|
attributes[MP42ChaptersPreviewPosition] = @([[NSUserDefaults standardUserDefaults] floatForKey:@"SBChaptersPreviewPosition"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
_attributes = [attributes copy];
|
_attributes = [attributes copy];
|
||||||
@@ -82,9 +88,9 @@
|
|||||||
|
|
||||||
NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
|
NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
|
||||||
|
|
||||||
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"chaptersPreviewTrack"] boolValue]) {
|
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"chaptersPreviewTrack"]) {
|
||||||
attributes[MP42GenerateChaptersPreviewTrack] = @YES;
|
attributes[MP42GenerateChaptersPreviewTrack] = @YES;
|
||||||
attributes[MP42ChaptersPreviewPosition] = [NSNumber numberWithFloat:[[NSUserDefaults standardUserDefaults] floatForKey:@"SBChaptersPreviewPosition"]];
|
attributes[MP42ChaptersPreviewPosition] = @([[NSUserDefaults standardUserDefaults] floatForKey:@"SBChaptersPreviewPosition"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
_attributes = [attributes copy];
|
_attributes = [attributes copy];
|
||||||
@@ -128,11 +134,35 @@
|
|||||||
|
|
||||||
#pragma mark Public methods
|
#pragma mark Public methods
|
||||||
|
|
||||||
- (void)setStatus:(SBQueueItemStatus)itemStatus {
|
- (void)setStatus:(SBQueueItemStatus)status {
|
||||||
_status = itemStatus;
|
dispatch_sync(_queue, ^{
|
||||||
if (_status == SBQueueItemStatusCompleted) {
|
self->_status = status;
|
||||||
self.mp4File = nil;
|
if (self->_status == SBQueueItemStatusCompleted) {
|
||||||
}
|
self.mp4File = nil;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
- (SBQueueItemStatus)status {
|
||||||
|
__block SBQueueItemStatus status;
|
||||||
|
dispatch_sync(_queue, ^{
|
||||||
|
status = self->_status;
|
||||||
|
});
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setFileURL:(NSURL * _Nonnull)fileURL {
|
||||||
|
dispatch_sync(_queue, ^{
|
||||||
|
self->_fileURL = fileURL;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSURL *)fileURL {
|
||||||
|
__block NSURL *fileURL;
|
||||||
|
dispatch_sync(_queue, ^{
|
||||||
|
fileURL = self->_fileURL;
|
||||||
|
});
|
||||||
|
return fileURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)addAction:(id<SBQueueActionProtocol>)action {
|
- (void)addAction:(id<SBQueueActionProtocol>)action {
|
||||||
@@ -370,11 +400,7 @@ bail:
|
|||||||
// Convert from a file reference url to a normal url
|
// Convert from a file reference url to a normal url
|
||||||
// the file will be replaced if optimized, and the reference url
|
// the file will be replaced if optimized, and the reference url
|
||||||
// may point to nil
|
// may point to nil
|
||||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
self.fileURL = filePathURL;
|
||||||
[self willChangeValueForKey:@"fileURL"];
|
|
||||||
self->_fileURL = filePathURL;
|
|
||||||
[self didChangeValueForKey:@"fileURL"];
|
|
||||||
});
|
|
||||||
|
|
||||||
#ifdef SB_SANDBOX
|
#ifdef SB_SANDBOX
|
||||||
if ([destination respondsToSelector:@selector(stopAccessingSecurityScopedResource)])
|
if ([destination respondsToSelector:@selector(stopAccessingSecurityScopedResource)])
|
||||||
@@ -415,7 +441,7 @@ bail:
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithCoder:(NSCoder *)decoder {
|
- (instancetype)initWithCoder:(NSCoder *)decoder {
|
||||||
self = [super init];
|
self = [self init];
|
||||||
|
|
||||||
if (self) {
|
if (self) {
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user