@@ -21,6 +21,9 @@ import WinSDK
2121import Bionic
2222#elseif canImport(wasi_pthread)
2323import wasi_pthread
24+ #elseif canImport(WASILibc)
25+ // No locking on WASILibc provided by the current Swift for WebAssembly SDK as of Dec 2025.
26+ // That SDK is also single-threaded, so we can safely avoid locking altogether.
2427#else
2528#error("Unsupported platform")
2629#endif
@@ -30,6 +33,8 @@ internal struct Lock {
3033 typealias Primitive = os_unfair_lock
3134 #elseif canImport(Glibc) || canImport(Musl) || canImport(Bionic) || canImport(wasi_pthread)
3235 typealias Primitive = pthread_mutex_t
36+ #elseif canImport(WASILibc)
37+ // This WASILibc variation is single threaded, provides no locks
3338 #elseif canImport(WinSDK)
3439 typealias Primitive = SRWLOCK
3540 #else
@@ -49,6 +54,8 @@ internal struct Lock {
4954 #elseif canImport(Glibc) || canImport(Musl) || canImport(Bionic) || canImport(wasi_pthread)
5055 let result = pthread_mutex_init ( platformLock, nil )
5156 precondition ( result == 0 , " pthread_mutex_init failed " )
57+ #elseif canImport(WASILibc)
58+ // This WASILibc variation is single threaded, provides no locks
5259 #elseif canImport(WinSDK)
5360 InitializeSRWLock ( platformLock)
5461 #else
@@ -69,6 +76,9 @@ internal struct Lock {
6976 os_unfair_lock_lock ( platformLock)
7077 #elseif canImport(Glibc) || canImport(Musl) || canImport(Bionic) || canImport(wasi_pthread)
7178 pthread_mutex_lock ( platformLock)
79+ #elseif canImport(WASILibc)
80+ // This WASILibc variation is single threaded, provides no locks
81+ return
7282 #elseif canImport(WinSDK)
7383 AcquireSRWLockExclusive ( platformLock)
7484 #else
@@ -82,6 +92,9 @@ internal struct Lock {
8292 #elseif canImport(Glibc) || canImport(Musl) || canImport(Bionic) || canImport(wasi_pthread)
8393 let result = pthread_mutex_unlock ( platformLock)
8494 precondition ( result == 0 , " pthread_mutex_unlock failed " )
95+ #elseif canImport(WASILibc)
96+ // This WASILibc variation is single threaded, provides no locks
97+ return
8598 #elseif canImport(WinSDK)
8699 ReleaseSRWLockExclusive ( platformLock)
87100 #else
0 commit comments