Browse Source

macosx: Fix deadlock when playqueue playback finishes

Signed-off-by: Claudio Cambra <developer@claudiocambra.com>
pull/192/head
Claudio Cambra 9 months ago
committed by Felix Paul Kühne
parent
commit
80397597e9
  1. 52
      modules/gui/macosx/library/VLCLibraryModel.m

52
modules/gui/macosx/library/VLCLibraryModel.m

@ -1260,15 +1260,15 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
} }
// Block calling queue while we modify the cache, preventing dangerous concurrent modification // Block calling queue while we modify the cache, preventing dangerous concurrent modification
dispatch_sync(dispatch_get_main_queue(), ^{ NSMutableArray * const mutableAudioGroupCache = [cache mutableCopy];
NSMutableArray * const mutableAudioGroupCache = [cache mutableCopy]; [mutableAudioGroupCache replaceObjectAtIndex:audioGroupIndex withObject:audioGroupItem];
[mutableAudioGroupCache replaceObjectAtIndex:audioGroupIndex withObject:audioGroupItem]; NSArray * const immutableCopy = [mutableAudioGroupCache copy];
NSArray * const immutableCopy = [mutableAudioGroupCache copy];
const IMP cacheSetterImp = [self methodForSelector:setterSelector]; const IMP cacheSetterImp = [self methodForSelector:setterSelector];
void (*cacheSetterFunction)(id, SEL, NSArray *) = (void *)cacheSetterImp; void (*cacheSetterFunction)(id, SEL, NSArray *) = (void *)cacheSetterImp;
cacheSetterFunction(self, setterSelector, immutableCopy); cacheSetterFunction(self, setterSelector, immutableCopy);
dispatch_async(dispatch_get_main_queue(), ^{
[self.changeDelegate notifyChange:notificationName withObject:audioGroupItem]; [self.changeDelegate notifyChange:notificationName withObject:audioGroupItem];
}); });
}); });
@ -1292,16 +1292,15 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
const id<VLCMediaLibraryAudioGroupProtocol> audioGroupItem = cache[audioGroupIndex]; const id<VLCMediaLibraryAudioGroupProtocol> audioGroupItem = cache[audioGroupIndex];
// Block calling queue while we modify the cache, preventing dangerous concurrent modification NSMutableArray * const mutableAudioGroupCache = [cache mutableCopy];
dispatch_sync(dispatch_get_main_queue(), ^{ [mutableAudioGroupCache removeObjectAtIndex:audioGroupIndex];
NSMutableArray * const mutableAudioGroupCache = [cache mutableCopy]; NSArray * const immutableCopy = [mutableAudioGroupCache copy];
[mutableAudioGroupCache removeObjectAtIndex:audioGroupIndex];
NSArray * const immutableCopy = [mutableAudioGroupCache copy];
const IMP cacheSetterImp = [self methodForSelector:setterSelector]; const IMP cacheSetterImp = [self methodForSelector:setterSelector];
void (*cacheSetterFunction)(id, SEL, NSArray *) = (void *)cacheSetterImp; void (*cacheSetterFunction)(id, SEL, NSArray *) = (void *)cacheSetterImp;
cacheSetterFunction(self, setterSelector, immutableCopy); cacheSetterFunction(self, setterSelector, immutableCopy);
dispatch_async(dispatch_get_main_queue(), ^{
[self.changeDelegate notifyChange:notificationName withObject:audioGroupItem]; [self.changeDelegate notifyChange:notificationName withObject:audioGroupItem];
}); });
}); });
@ -1423,12 +1422,13 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
return; return;
} }
dispatch_sync(dispatch_get_main_queue(), ^{ VLCMediaLibraryGroup * const groupToDelete = mutableGroups[groupIdx];
VLCMediaLibraryGroup * const group = mutableGroups[groupIdx]; [mutableGroups removeObjectAtIndex:groupIdx];
[mutableGroups removeObjectAtIndex:groupIdx]; self.cachedListOfGroups = mutableGroups.copy;
self.cachedListOfGroups = mutableGroups.copy;
dispatch_async(dispatch_get_main_queue(), ^{
[self->_defaultNotificationCenter postNotificationName:VLCLibraryModelGroupDeleted [self->_defaultNotificationCenter postNotificationName:VLCLibraryModelGroupDeleted
object:group]; object:groupToDelete];
}); });
}); });
} }
@ -1458,11 +1458,13 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
return; return;
} }
dispatch_sync(dispatch_get_main_queue(), ^{ NSMutableArray * const mutableGroups = self.cachedListOfGroups.mutableCopy;
NSMutableArray * const mutableGroups = self.cachedListOfGroups.mutableCopy; [mutableGroups replaceObjectAtIndex:groupIdx withObject:group];
[mutableGroups replaceObjectAtIndex:groupIdx withObject:group]; self.cachedListOfGroups = mutableGroups.copy;
self.cachedListOfGroups = mutableGroups.copy;
[self->_defaultNotificationCenter postNotificationName:VLCLibraryModelGroupUpdated object:group]; dispatch_async(dispatch_get_main_queue(), ^{
[self->_defaultNotificationCenter postNotificationName:VLCLibraryModelGroupUpdated
object:group];
}); });
}); });
} }

Loading…
Cancel
Save