@@ -52,12 +52,12 @@ extension LockOperations {
52
52
debugOnly {
53
53
pthread_mutexattr_settype ( & attr, . init( PTHREAD_MUTEX_ERRORCHECK) )
54
54
}
55
-
55
+
56
56
let err = pthread_mutex_init ( mutex, & attr)
57
57
precondition ( err == 0 , " \( #function) failed in pthread_mutex with error \( err) " )
58
58
#endif
59
59
}
60
-
60
+
61
61
@inlinable
62
62
static func destroy( _ mutex: UnsafeMutablePointer < LockPrimitive > ) {
63
63
mutex. assertValidAlignment ( )
@@ -69,7 +69,7 @@ extension LockOperations {
69
69
precondition ( err == 0 , " \( #function) failed in pthread_mutex with error \( err) " )
70
70
#endif
71
71
}
72
-
72
+
73
73
@inlinable
74
74
static func lock( _ mutex: UnsafeMutablePointer < LockPrimitive > ) {
75
75
mutex. assertValidAlignment ( )
@@ -81,7 +81,7 @@ extension LockOperations {
81
81
precondition ( err == 0 , " \( #function) failed in pthread_mutex with error \( err) " )
82
82
#endif
83
83
}
84
-
84
+
85
85
@inlinable
86
86
static func unlock( _ mutex: UnsafeMutablePointer < LockPrimitive > ) {
87
87
mutex. assertValidAlignment ( )
@@ -125,49 +125,50 @@ extension LockOperations {
125
125
// See also: https://github.com/apple/swift/pull/40000
126
126
@usableFromInline
127
127
final class LockStorage < Value> : ManagedBuffer < Value , LockPrimitive > {
128
-
128
+
129
129
@inlinable
130
130
static func create( value: Value ) -> Self {
131
131
let buffer = Self . create ( minimumCapacity: 1 ) { _ in
132
132
return value
133
133
}
134
- let storage = unsafeDowncast ( buffer, to: Self . self)
135
-
134
+ // Avoid 'unsafeDowncast' as there is a miscompilation on 5.10.
135
+ let storage = buffer as! Self
136
+
136
137
storage. withUnsafeMutablePointers { _, lockPtr in
137
138
LockOperations . create ( lockPtr)
138
139
}
139
-
140
+
140
141
return storage
141
142
}
142
-
143
+
143
144
@inlinable
144
145
func lock( ) {
145
146
self . withUnsafeMutablePointerToElements { lockPtr in
146
147
LockOperations . lock ( lockPtr)
147
148
}
148
149
}
149
-
150
+
150
151
@inlinable
151
152
func unlock( ) {
152
153
self . withUnsafeMutablePointerToElements { lockPtr in
153
154
LockOperations . unlock ( lockPtr)
154
155
}
155
156
}
156
-
157
+
157
158
@inlinable
158
159
deinit {
159
160
self . withUnsafeMutablePointerToElements { lockPtr in
160
161
LockOperations . destroy ( lockPtr)
161
162
}
162
163
}
163
-
164
+
164
165
@inlinable
165
166
func withLockPrimitive< T> ( _ body: ( UnsafeMutablePointer < LockPrimitive > ) throws -> T ) rethrows -> T {
166
167
try self . withUnsafeMutablePointerToElements { lockPtr in
167
168
return try body ( lockPtr)
168
169
}
169
170
}
170
-
171
+
171
172
@inlinable
172
173
func withLockedValue< T> ( _ mutate: ( inout Value ) throws -> T ) rethrows -> T {
173
174
try self . withUnsafeMutablePointers { valuePtr, lockPtr in
@@ -192,7 +193,7 @@ extension LockStorage: @unchecked Sendable { }
192
193
struct NIOLock {
193
194
@usableFromInline
194
195
internal let _storage : LockStorage < Void >
195
-
196
+
196
197
/// Create a new lock.
197
198
@inlinable
198
199
init ( ) {
0 commit comments