@@ -46,21 +46,16 @@ import wasi_pthread
4646#endif
4747
4848#if os(Windows)
49- @usableFromInline
5049typealias LockPrimitive = SRWLOCK
5150#elseif canImport(Darwin)
52- @usableFromInline
5351typealias LockPrimitive = os_unfair_lock
5452#else
55- @usableFromInline
5653typealias LockPrimitive = pthread_mutex_t
5754#endif
5855
59- @usableFromInline
6056enum LockOperations { }
6157
6258extension LockOperations {
63- @inlinable
6459 static func create( _ mutex: UnsafeMutablePointer < LockPrimitive > ) {
6560 mutex. assertValidAlignment ( )
6661
@@ -77,7 +72,6 @@ extension LockOperations {
7772 #endif
7873 }
7974
80- @inlinable
8175 static func destroy( _ mutex: UnsafeMutablePointer < LockPrimitive > ) {
8276 mutex. assertValidAlignment ( )
8377
@@ -91,7 +85,6 @@ extension LockOperations {
9185 #endif
9286 }
9387
94- @inlinable
9588 static func lock( _ mutex: UnsafeMutablePointer < LockPrimitive > ) {
9689 mutex. assertValidAlignment ( )
9790
@@ -105,7 +98,6 @@ extension LockOperations {
10598 #endif
10699 }
107100
108- @inlinable
109101 static func unlock( _ mutex: UnsafeMutablePointer < LockPrimitive > ) {
110102 mutex. assertValidAlignment ( )
111103
@@ -148,10 +140,8 @@ extension LockOperations {
148140// and future maintainers will be happier that we were cautious.
149141//
150142// See also: https://github.com/apple/swift/pull/40000
151- @usableFromInline
152143final class LockStorage < Value> : ManagedBuffer < Value , LockPrimitive > {
153144
154- @inlinable
155145 static func create( value: Value ) -> Self {
156146 let buffer = Self . create ( minimumCapacity: 1 ) { _ in
157147 value
@@ -168,35 +158,30 @@ final class LockStorage<Value>: ManagedBuffer<Value, LockPrimitive> {
168158 return storage
169159 }
170160
171- @inlinable
172161 func lock( ) {
173162 self . withUnsafeMutablePointerToElements { lockPtr in
174163 LockOperations . lock ( lockPtr)
175164 }
176165 }
177166
178- @inlinable
179167 func unlock( ) {
180168 self . withUnsafeMutablePointerToElements { lockPtr in
181169 LockOperations . unlock ( lockPtr)
182170 }
183171 }
184172
185- @inlinable
186173 deinit {
187174 self . withUnsafeMutablePointerToElements { lockPtr in
188175 LockOperations . destroy ( lockPtr)
189176 }
190177 }
191178
192- @inlinable
193179 func withLockPrimitive< T> ( _ body: ( UnsafeMutablePointer < LockPrimitive > ) throws -> T ) rethrows -> T {
194180 try self . withUnsafeMutablePointerToElements { lockPtr in
195181 try body ( lockPtr)
196182 }
197183 }
198184
199- @inlinable
200185 func withLockedValue< T> ( _ mutate: ( inout Value ) throws -> T ) rethrows -> T {
201186 try self . withUnsafeMutablePointers { valuePtr, lockPtr in
202187 LockOperations . lock ( lockPtr)
@@ -209,7 +194,6 @@ final class LockStorage<Value>: ManagedBuffer<Value, LockPrimitive> {
209194extension LockStorage : @unchecked Sendable { }
210195
211196extension UnsafeMutablePointer {
212- @inlinable
213197 func assertValidAlignment( ) {
214198 assert ( UInt ( bitPattern: self ) % UInt( MemoryLayout< Pointee> . alignment) == 0 )
215199 }
0 commit comments