From 827654c0c1f37040f1476591644c3883041574cc Mon Sep 17 00:00:00 2001 From: tzugen Date: Thu, 21 Apr 2022 20:24:43 +0200 Subject: [PATCH] Create lock before launching the coroutine, return always a copy of the list and not the real one. --- .../org/moire/ultrasonic/playback/LegacyPlaylistManager.kt | 2 +- .../org/moire/ultrasonic/service/PlaybackStateSerializer.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/playback/LegacyPlaylistManager.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/playback/LegacyPlaylistManager.kt index 0afaccd2..74cf6a8a 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/playback/LegacyPlaylistManager.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/playback/LegacyPlaylistManager.kt @@ -77,7 +77,7 @@ class LegacyPlaylistManager : KoinComponent { // Public facing playlist (immutable) val playlist: List - get() = _playlist + get() = _playlist.toList() @get:Synchronized val playlistDuration: Long diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/PlaybackStateSerializer.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/PlaybackStateSerializer.kt index a8d62a7c..6d015cb5 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/PlaybackStateSerializer.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/PlaybackStateSerializer.kt @@ -43,8 +43,8 @@ class PlaybackStateSerializer : KoinComponent { ) { if (!setup.get()) return - ioScope.launch { - if (lock.tryLock()) { + if (lock.tryLock()) { + ioScope.launch { try { serializeNow(songs, currentPlayingIndex, currentPlayingPosition) } finally {