37
37
@available ( macOS, deprecated: 13.0 , message: " use OSAllocatedUnfairLock directly " )
38
38
public struct AllocatedLock < State> {
39
39
40
- private let storage : Storage
40
+ @usableFromInline
41
+ let storage : Storage
41
42
42
43
public init ( initialState: State ) {
43
44
self . storage = Storage ( initialState: initialState)
44
45
}
45
46
47
+ @inlinable
46
48
public func withLock< R> ( _ body: @Sendable ( inout State ) throws -> R ) rethrows -> R where R: Sendable {
47
49
storage. lock ( )
48
50
defer { storage. unlock ( ) }
@@ -56,14 +58,17 @@ public extension AllocatedLock where State == Void {
56
58
self . storage = Storage ( initialState: ( ) )
57
59
}
58
60
61
+ @inlinable
59
62
func lock( ) {
60
63
storage. lock ( )
61
64
}
62
65
66
+ @inlinable
63
67
func unlock( ) {
64
68
storage. unlock ( )
65
69
}
66
70
71
+ @inlinable
67
72
func withLock< R> ( _ body: @Sendable ( ) throws -> R ) rethrows -> R where R: Sendable {
68
73
storage. lock ( )
69
74
defer { storage. unlock ( ) }
@@ -74,9 +79,12 @@ public extension AllocatedLock where State == Void {
74
79
#if canImport(Darwin)
75
80
@_implementationOnly import os
76
81
77
- private extension AllocatedLock {
82
+ extension AllocatedLock {
83
+ @usableFromInline
78
84
final class Storage {
79
85
private let _lock : os_unfair_lock_t
86
+
87
+ @usableFromInline
80
88
var state : State
81
89
82
90
init ( initialState: State ) {
@@ -85,10 +93,12 @@ private extension AllocatedLock {
85
93
self . state = initialState
86
94
}
87
95
96
+ @usableFromInline
88
97
func lock( ) {
89
98
os_unfair_lock_lock ( _lock)
90
99
}
91
100
101
+ @usableFromInline
92
102
func unlock( ) {
93
103
os_unfair_lock_unlock ( _lock)
94
104
}
@@ -103,10 +113,12 @@ private extension AllocatedLock {
103
113
#elseif canImport(Glibc)
104
114
@_implementationOnly import Glibc
105
115
106
- private extension AllocatedLock {
116
+ extension AllocatedLock {
117
+ @usableFromInline
107
118
final class Storage {
108
119
private let _lock : UnsafeMutablePointer < pthread_mutex_t >
109
120
121
+ @usableFromInline
110
122
var state : State
111
123
112
124
init ( initialState: State ) {
@@ -118,11 +130,13 @@ private extension AllocatedLock {
118
130
self . state = initialState
119
131
}
120
132
133
+ @usableFromInline
121
134
func lock( ) {
122
135
let err = pthread_mutex_lock ( _lock)
123
136
precondition ( err == 0 , " pthread_mutex_lock error: \( err) " )
124
137
}
125
138
139
+ @usableFromInline
126
140
func unlock( ) {
127
141
let err = pthread_mutex_unlock ( _lock)
128
142
precondition ( err == 0 , " pthread_mutex_unlock error: \( err) " )
0 commit comments