@@ -19,9 +19,15 @@ import Musl
1919import WinSDK
2020#elseif canImport(Bionic)
2121import Bionic
22- #elseif canImport(wasi_pthread)
22+ #elseif canImport(WASILibc)
23+ #if canImport(wasi_pthread)
24+ import WASILibc
2325import wasi_pthread
2426#else
27+ // No locking on WASILibc provided by the current Swift for WebAssembly SDK as of Dec 2025.
28+ // That SDK is also single-threaded, so we can safely avoid locking altogether.
29+ #endif // canImport(wasi_pthread)
30+ #else
2531#error("Unsupported platform")
2632#endif
2733
@@ -30,6 +36,8 @@ internal struct Lock {
3036 typealias Primitive = os_unfair_lock
3137 #elseif canImport(Glibc) || canImport(Musl) || canImport(Bionic) || canImport(wasi_pthread)
3238 typealias Primitive = pthread_mutex_t
39+ #elseif canImport(WASILibc)
40+ // This WASILibc variation is single threaded, provides no locks
3341 #elseif canImport(WinSDK)
3442 typealias Primitive = SRWLOCK
3543 #else
@@ -49,6 +57,8 @@ internal struct Lock {
4957 #elseif canImport(Glibc) || canImport(Musl) || canImport(Bionic) || canImport(wasi_pthread)
5058 let result = pthread_mutex_init ( platformLock, nil )
5159 precondition ( result == 0 , " pthread_mutex_init failed " )
60+ #elseif canImport(WASILibc)
61+ // This WASILibc variation is single threaded, provides no locks
5262 #elseif canImport(WinSDK)
5363 InitializeSRWLock ( platformLock)
5464 #else
@@ -69,6 +79,9 @@ internal struct Lock {
6979 os_unfair_lock_lock ( platformLock)
7080 #elseif canImport(Glibc) || canImport(Musl) || canImport(Bionic) || canImport(wasi_pthread)
7181 pthread_mutex_lock ( platformLock)
82+ #elseif canImport(WASILibc)
83+ // This WASILibc variation is single threaded, provides no locks
84+ return
7285 #elseif canImport(WinSDK)
7386 AcquireSRWLockExclusive ( platformLock)
7487 #else
@@ -82,6 +95,9 @@ internal struct Lock {
8295 #elseif canImport(Glibc) || canImport(Musl) || canImport(Bionic) || canImport(wasi_pthread)
8396 let result = pthread_mutex_unlock ( platformLock)
8497 precondition ( result == 0 , " pthread_mutex_unlock failed " )
98+ #elseif canImport(WASILibc)
99+ // This WASILibc variation is single threaded, provides no locks
100+ return
85101 #elseif canImport(WinSDK)
86102 ReleaseSRWLockExclusive ( platformLock)
87103 #else
0 commit comments