3737@available ( macOS, deprecated: 13.0 , message: " use OSAllocatedUnfairLock directly " )
3838public struct AllocatedLock < State> {
3939
40- private let storage : Storage
40+ @usableFromInline
41+ let storage : Storage
4142
4243 public init ( initialState: State ) {
4344 self . storage = Storage ( initialState: initialState)
4445 }
4546
47+ @inlinable
4648 public func withLock< R> ( _ body: @Sendable ( inout State ) throws -> R ) rethrows -> R where R: Sendable {
4749 storage. lock ( )
4850 defer { storage. unlock ( ) }
@@ -56,14 +58,17 @@ public extension AllocatedLock where State == Void {
5658 self . storage = Storage ( initialState: ( ) )
5759 }
5860
61+ @inlinable
5962 func lock( ) {
6063 storage. lock ( )
6164 }
6265
66+ @inlinable
6367 func unlock( ) {
6468 storage. unlock ( )
6569 }
6670
71+ @inlinable
6772 func withLock< R> ( _ body: @Sendable ( ) throws -> R ) rethrows -> R where R: Sendable {
6873 storage. lock ( )
6974 defer { storage. unlock ( ) }
@@ -74,9 +79,12 @@ public extension AllocatedLock where State == Void {
7479#if canImport(Darwin)
7580@_implementationOnly import os
7681
77- private extension AllocatedLock {
82+ extension AllocatedLock {
83+ @usableFromInline
7884 final class Storage {
7985 private let _lock : os_unfair_lock_t
86+
87+ @usableFromInline
8088 var state : State
8189
8290 init ( initialState: State ) {
@@ -85,10 +93,12 @@ private extension AllocatedLock {
8593 self . state = initialState
8694 }
8795
96+ @usableFromInline
8897 func lock( ) {
8998 os_unfair_lock_lock ( _lock)
9099 }
91100
101+ @usableFromInline
92102 func unlock( ) {
93103 os_unfair_lock_unlock ( _lock)
94104 }
@@ -103,10 +113,12 @@ private extension AllocatedLock {
103113#elseif canImport(Glibc)
104114@_implementationOnly import Glibc
105115
106- private extension AllocatedLock {
116+ extension AllocatedLock {
117+ @usableFromInline
107118 final class Storage {
108119 private let _lock : UnsafeMutablePointer < pthread_mutex_t >
109120
121+ @usableFromInline
110122 var state : State
111123
112124 init ( initialState: State ) {
@@ -118,11 +130,13 @@ private extension AllocatedLock {
118130 self . state = initialState
119131 }
120132
133+ @usableFromInline
121134 func lock( ) {
122135 let err = pthread_mutex_lock ( _lock)
123136 precondition ( err == 0 , " pthread_mutex_lock error: \( err) " )
124137 }
125138
139+ @usableFromInline
126140 func unlock( ) {
127141 let err = pthread_mutex_unlock ( _lock)
128142 precondition ( err == 0 , " pthread_mutex_unlock error: \( err) " )
0 commit comments