Skip to content

Commit 1146b41

Browse files
committed
Add the underscored unsafe locking primitives
1 parent 882568c commit 1146b41

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

stdlib/public/Synchronization/Mutex/Mutex.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ public struct Mutex<Value: ~Copyable>: ~Copyable {
5252
public init(_ initialValue: consuming Value) {
5353
value = _Cell(initialValue)
5454
}
55+
}
5556

57+
@available(SwiftStdlib 6.0, *)
58+
extension Mutex {
5659
/// Attempts to acquire the lock and then calls the given closure if
5760
/// successful.
5861
///
@@ -204,5 +207,29 @@ public struct Mutex<Value: ~Copyable>: ~Copyable {
204207
}
205208
}
206209

210+
@available(SwiftStdlib 6.0, *)
211+
extension Mutex where Value == Void {
212+
@available(SwiftStdlib 6.0, *)
213+
@_alwaysEmitIntoClient
214+
@_transparent
215+
public borrowing func _unsafeLock() {
216+
handle.lock()
217+
}
218+
219+
@available(SwiftStdlib 6.0, *)
220+
@_alwaysEmitIntoClient
221+
@_transparent
222+
public borrowing func _unsafeTryLock() -> Bool {
223+
handle.tryLock()
224+
}
225+
226+
@available(SwiftStdlib 6.0, *)
227+
@_alwaysEmitIntoClient
228+
@_transparent
229+
public borrowing func _unsafeUnlock() {
230+
handle.unlock()
231+
}
232+
}
233+
207234
@available(SwiftStdlib 6.0, *)
208235
extension Mutex: @unchecked Sendable where Value: Sendable {}

0 commit comments

Comments
 (0)