Skip to content

Commit 7605549

Browse files
committed
wip
1 parent c4ffeb3 commit 7605549

File tree

1 file changed

+3
-16
lines changed

1 file changed

+3
-16
lines changed

Sources/ConcurrencyExtras/Mutex.swift

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,25 @@
44
/// A synchronization primitive that protects shared mutable state via mutual exclusion.
55
///
66
/// A back-port of Swift's `Mutex` type for wider platform availability.
7-
@frozen
87
@_staticExclusiveOnly
98
@available(iOS, obsoleted: 18, message: "Use 'Synchronization.Mutex', instead.")
109
@available(macOS, obsoleted: 15, message: "Use 'Synchronization.Mutex', instead.")
1110
@available(tvOS, obsoleted: 18, message: "Use 'Synchronization.Mutex', instead.")
1211
@available(visionOS, obsoleted: 2, message: "Use 'Synchronization.Mutex', instead.")
1312
@available(watchOS, obsoleted: 11, message: "Use 'Synchronization.Mutex', instead.")
1413
public struct Mutex<Value: ~Copyable>: ~Copyable {
15-
@usableFromInline
16-
let _lock = NSLock()
17-
18-
@usableFromInline
19-
let _box: Box
14+
private let _lock = NSLock()
15+
private let _box: Box
2016

2117
/// Initializes a value of this mutex with the given initial state.
2218
///
2319
/// - Parameter initialValue: The initial value to give to the mutex.
24-
@_transparent
2520
public init(_ initialValue: consuming sending Value) {
2621
_box = Box(initialValue)
2722
}
2823

29-
@usableFromInline
30-
final class Box {
31-
@usableFromInline
24+
private final class Box {
3225
var value: Value
33-
@usableFromInline
3426
init(_ initialValue: consuming sending Value) {
3527
value = initialValue
3628
}
@@ -41,7 +33,6 @@
4133

4234
extension Mutex where Value: ~Copyable {
4335
/// Calls the given closure after acquiring the lock and then releases ownership.
44-
@_transparent
4536
public borrowing func withLock<Result: ~Copyable, E: Error>(
4637
_ body: (inout sending Value) throws(E) -> sending Result
4738
) throws(E) -> sending Result {
@@ -51,7 +42,6 @@
5142
}
5243

5344
/// Attempts to acquire the lock and then calls the given closure if successful.
54-
@_transparent
5545
public borrowing func withLockIfAvailable<Result: ~Copyable, E: Error>(
5646
_ body: (inout sending Value) throws(E) -> sending Result
5747
) throws(E) -> sending Result? {
@@ -62,17 +52,14 @@
6252
}
6353

6454
extension Mutex where Value == Void {
65-
@_transparent
6655
public borrowing func _unsafeLock() {
6756
_lock.lock()
6857
}
6958

70-
@_transparent
7159
public borrowing func _unsafeTryLock() -> Bool {
7260
_lock.try()
7361
}
7462

75-
@_transparent
7663
public borrowing func _unsafeUnlock() {
7764
_lock.unlock()
7865
}

0 commit comments

Comments
 (0)