From 88fb82d19337fbb1f329f3686acac9ed557ff594 Mon Sep 17 00:00:00 2001 From: Jeremy Schonfeld Date: Fri, 20 Dec 2024 13:42:12 -0800 Subject: [PATCH] Implement LockedState for Musl (#1101) --- Sources/FoundationEssentials/LockedState.swift | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Sources/FoundationEssentials/LockedState.swift b/Sources/FoundationEssentials/LockedState.swift index ac7539f1b..0cca43328 100644 --- a/Sources/FoundationEssentials/LockedState.swift +++ b/Sources/FoundationEssentials/LockedState.swift @@ -46,17 +46,19 @@ package struct LockedState { fileprivate static func initialize(_ platformLock: PlatformLock) { #if canImport(os) platformLock.initialize(to: os_unfair_lock()) -#elseif canImport(Bionic) || canImport(Glibc) +#elseif canImport(Bionic) || canImport(Glibc) || canImport(Musl) pthread_mutex_init(platformLock, nil) #elseif canImport(WinSDK) InitializeSRWLock(platformLock) #elseif os(WASI) // no-op +#else +#error("LockedState._Lock.initialize is unimplemented on this platform") #endif } fileprivate static func deinitialize(_ platformLock: PlatformLock) { -#if canImport(Bionic) || canImport(Glibc) +#if canImport(Bionic) || canImport(Glibc) || canImport(Musl) pthread_mutex_destroy(platformLock) #endif platformLock.deinitialize(count: 1) @@ -65,24 +67,28 @@ package struct LockedState { static fileprivate func lock(_ platformLock: PlatformLock) { #if canImport(os) os_unfair_lock_lock(platformLock) -#elseif canImport(Bionic) || canImport(Glibc) +#elseif canImport(Bionic) || canImport(Glibc) || canImport(Musl) pthread_mutex_lock(platformLock) #elseif canImport(WinSDK) AcquireSRWLockExclusive(platformLock) #elseif os(WASI) // no-op +#else +#error("LockedState._Lock.lock is unimplemented on this platform") #endif } static fileprivate func unlock(_ platformLock: PlatformLock) { #if canImport(os) os_unfair_lock_unlock(platformLock) -#elseif canImport(Bionic) || canImport(Glibc) +#elseif canImport(Bionic) || canImport(Glibc) || canImport(Musl) pthread_mutex_unlock(platformLock) #elseif canImport(WinSDK) ReleaseSRWLockExclusive(platformLock) #elseif os(WASI) // no-op +#else +#error("LockedState._Lock.unlock is unimplemented on this platform") #endif } }