File tree 2 files changed +17
-0
lines changed
Sources/FoundationEssentials
2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,9 @@ package struct LockedState<State> {
33
33
typealias Primitive = pthread_mutex_t
34
34
#elseif canImport(WinSDK)
35
35
typealias Primitive = SRWLOCK
36
+ #elseif os(WASI)
37
+ // WASI is single-threaded, so we don't need a lock.
38
+ typealias Primitive = Void
36
39
#endif
37
40
38
41
typealias PlatformLock = UnsafeMutablePointer < Primitive >
@@ -45,6 +48,8 @@ package struct LockedState<State> {
45
48
pthread_mutex_init ( platformLock, nil )
46
49
#elseif canImport(WinSDK)
47
50
InitializeSRWLock ( platformLock)
51
+ #elseif os(WASI)
52
+ // no-op
48
53
#endif
49
54
}
50
55
@@ -62,6 +67,8 @@ package struct LockedState<State> {
62
67
pthread_mutex_lock ( platformLock)
63
68
#elseif canImport(WinSDK)
64
69
AcquireSRWLockExclusive ( platformLock)
70
+ #elseif os(WASI)
71
+ // no-op
65
72
#endif
66
73
}
67
74
@@ -72,6 +79,8 @@ package struct LockedState<State> {
72
79
pthread_mutex_unlock ( platformLock)
73
80
#elseif canImport(WinSDK)
74
81
ReleaseSRWLockExclusive ( platformLock)
82
+ #elseif os(WASI)
83
+ // no-op
75
84
#endif
76
85
}
77
86
}
Original file line number Diff line number Diff line change @@ -30,6 +30,8 @@ struct _ThreadLocal {
30
30
fileprivate typealias PlatformKey = tss_t
31
31
#elseif canImport(WinSDK)
32
32
fileprivate typealias PlatformKey = DWORD
33
+ #elseif os(WASI)
34
+ fileprivate typealias PlatformKey = UnsafeMutablePointer < UnsafeMutableRawPointer ? >
33
35
#endif
34
36
35
37
struct Key < Value> {
@@ -46,6 +48,8 @@ struct _ThreadLocal {
46
48
self . key = key
47
49
#elseif canImport(WinSDK)
48
50
key = FlsAlloc ( nil )
51
+ #elseif os(WASI)
52
+ key = UnsafeMutablePointer< UnsafeMutableRawPointer?> . allocate( capacity: 1 )
49
53
#endif
50
54
}
51
55
}
@@ -58,6 +62,8 @@ struct _ThreadLocal {
58
62
tss_get ( key)
59
63
#elseif canImport(WinSDK)
60
64
FlsGetValue ( key)
65
+ #elseif os(WASI)
66
+ key. pointee
61
67
#endif
62
68
}
63
69
@@ -68,6 +74,8 @@ struct _ThreadLocal {
68
74
tss_set ( key, newValue)
69
75
#elseif canImport(WinSDK)
70
76
FlsSetValue ( key, newValue)
77
+ #elseif os(WASI)
78
+ key. pointee = newValue
71
79
#endif
72
80
}
73
81
}
You can’t perform that action at this time.
0 commit comments