From ac44ca33b0bc0f133308a2b6b2d201252b662989 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Thu, 1 Sep 2016 17:20:53 -0700 Subject: [PATCH] Hopefully fixed total play time synchronizing with adding new tracks to the playlist. --- Playlist/PlaylistLoader.m | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Playlist/PlaylistLoader.m b/Playlist/PlaylistLoader.m index 03e9bece2..326b97c74 100755 --- a/Playlist/PlaylistLoader.m +++ b/Playlist/PlaylistLoader.m @@ -8,6 +8,8 @@ #include +#include + #import "PlaylistLoader.h" #import "PlaylistController.h" #import "PlaylistEntry.h" @@ -475,6 +477,11 @@ NSMutableDictionary * dictionaryWithPropertiesOfObject(id obj, NSArray * filterL if (!i) return; + semaphore_t info_sem; + semaphore_create( mach_task_self(), &info_sem, SYNC_POLICY_FIFO, (int) -i + 1 ); + + __block semaphore_t weak_sem = info_sem; + for (NSArray *a in array) { if (![a count]) continue; @@ -497,6 +504,7 @@ NSMutableDictionary * dictionaryWithPropertiesOfObject(id obj, NSArray * filterL dispatch_async(dispatch_get_main_queue(), ^{ [weakPe setMetadata:entryInfo]; + semaphore_signal(weak_sem); }); } }]; @@ -505,6 +513,9 @@ NSMutableDictionary * dictionaryWithPropertiesOfObject(id obj, NSArray * filterL } [queue waitUntilAllOperationsAreFinished]; + + semaphore_wait(info_sem); + semaphore_destroy(mach_task_self(), info_sem); [playlistController performSelectorOnMainThread:@selector(updateTotalTime) withObject:nil waitUntilDone:NO]; }