[AltServer] Replaces lock with semaphore when updating app groups

Locks can’t be unlocked from a separate thread than they were locked on…whoops.
This commit is contained in:
Riley Testut
2022-03-29 19:47:46 -07:00
parent 48c49c6ec7
commit b0abf0e7a5

View File

@@ -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<ALTAppID, Error>)
{
appGroupsLock.unlock()
appGroupsSemaphore.signal()
completionHandler(result)
}