From b0abf0e7a583287cb704ca8331991947bdbb641d Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Tue, 29 Mar 2022 19:47:46 -0700 Subject: [PATCH] [AltServer] Replaces lock with semaphore when updating app groups MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Locks can’t be unlocked from a separate thread than they were locked on…whoops. --- AltServer/Devices/ALTDeviceManager+Installation.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/AltServer/Devices/ALTDeviceManager+Installation.swift b/AltServer/Devices/ALTDeviceManager+Installation.swift index 47f38af3..d89a2e88 100644 --- a/AltServer/Devices/ALTDeviceManager+Installation.swift +++ b/AltServer/Devices/ALTDeviceManager+Installation.swift @@ -10,7 +10,7 @@ import Cocoa import UserNotifications import ObjectiveC -private let appGroupsLock = NSLock() +private let appGroupsSemaphore = DispatchSemaphore(value: 1) private let developerDiskManager = DeveloperDiskManager() @@ -680,16 +680,16 @@ private extension ALTDeviceManager } } - // Dispatch onto global queue to prevent appGroupsLock deadlock. + // Dispatch onto global queue to prevent appGroupsSemaphore deadlock. DispatchQueue.global().async { // Ensure we're not concurrently fetching and updating app groups, // which can lead to race conditions such as adding an app group twice. - appGroupsLock.lock() + appGroupsSemaphore.wait() func finish(_ result: Result) { - appGroupsLock.unlock() + appGroupsSemaphore.signal() completionHandler(result) }