@@ -36,12 +36,12 @@ struct Locked<T>: RawRepresentable, Sendable where T: Sendable {
36
36
/// To keep the implementation of this type as simple as possible,
37
37
/// `pthread_mutex_t` is used on Apple platforms instead of `os_unfair_lock`
38
38
/// or `OSAllocatedUnfairLock`.
39
- #if SWT_TARGET_OS_APPLE || os(Linux)
39
+ #if SWT_TARGET_OS_APPLE || os(Linux) || (os(WASI) && compiler(>=6.0) && _runtime(_multithreaded))
40
40
private typealias _Lock = pthread_mutex_t
41
41
#elseif os(Windows)
42
42
private typealias _Lock = SRWLOCK
43
43
#elseif os(WASI)
44
- // No locks on WASI.
44
+ // No locks on WASI without multithreaded runtime .
45
45
#else
46
46
#warning("Platform-specific implementation missing: locking unavailable")
47
47
private typealias _Lock = Void
@@ -51,12 +51,12 @@ struct Locked<T>: RawRepresentable, Sendable where T: Sendable {
51
51
private final class _Storage : ManagedBuffer < T , _Lock > {
52
52
deinit {
53
53
withUnsafeMutablePointerToElements { lock in
54
- #if SWT_TARGET_OS_APPLE || os(Linux)
54
+ #if SWT_TARGET_OS_APPLE || os(Linux) || (os(WASI) && compiler(>=6.0) && _runtime(_multithreaded))
55
55
_ = pthread_mutex_destroy ( lock)
56
56
#elseif os(Windows)
57
57
// No deinitialization needed.
58
58
#elseif os(WASI)
59
- // No locks on WASI.
59
+ // No locks on WASI without multithreaded runtime .
60
60
#else
61
61
#warning("Platform-specific implementation missing: locking unavailable")
62
62
#endif
@@ -70,12 +70,12 @@ struct Locked<T>: RawRepresentable, Sendable where T: Sendable {
70
70
init ( rawValue: T ) {
71
71
let storage = _Storage. create ( minimumCapacity: 1 , makingHeaderWith: { _ in rawValue } )
72
72
storage. withUnsafeMutablePointerToElements { lock in
73
- #if SWT_TARGET_OS_APPLE || os(Linux)
73
+ #if SWT_TARGET_OS_APPLE || os(Linux) || (os(WASI) && compiler(>=6.0) && _runtime(_multithreaded))
74
74
_ = pthread_mutex_init ( lock, nil )
75
75
#elseif os(Windows)
76
76
InitializeSRWLock ( lock)
77
77
#elseif os(WASI)
78
- // No locks on WASI.
78
+ // No locks on WASI without multithreaded runtime .
79
79
#else
80
80
#warning("Platform-specific implementation missing: locking unavailable")
81
81
#endif
@@ -101,7 +101,7 @@ struct Locked<T>: RawRepresentable, Sendable where T: Sendable {
101
101
/// concurrency tools.
102
102
nonmutating func withLock< R> ( _ body: ( inout T ) throws -> R ) rethrows -> R {
103
103
try _storage. rawValue. withUnsafeMutablePointers { rawValue, lock in
104
- #if SWT_TARGET_OS_APPLE || os(Linux)
104
+ #if SWT_TARGET_OS_APPLE || os(Linux) || (os(WASI) && compiler(>=6.0) && _runtime(_multithreaded))
105
105
_ = pthread_mutex_lock ( lock)
106
106
defer {
107
107
_ = pthread_mutex_unlock ( lock)
@@ -112,7 +112,7 @@ struct Locked<T>: RawRepresentable, Sendable where T: Sendable {
112
112
ReleaseSRWLockExclusive ( lock)
113
113
}
114
114
#elseif os(WASI)
115
- // No locks on WASI.
115
+ // No locks on WASI without multithreaded runtime .
116
116
#else
117
117
#warning("Platform-specific implementation missing: locking unavailable")
118
118
#endif
@@ -150,11 +150,6 @@ extension Locked where T: Numeric {
150
150
}
151
151
152
152
extension Locked {
153
- /// Initialize an instance of this type with a raw value of `0`.
154
- init ( ) where T: AdditiveArithmetic {
155
- self . init ( rawValue: . zero)
156
- }
157
-
158
153
/// Initialize an instance of this type with a raw value of `nil`.
159
154
init < V> ( ) where T == V ? {
160
155
self . init ( rawValue: nil )
0 commit comments