Skip to content

Commit b3d1e42

Browse files
committed
swift-mutex
1 parent b512776 commit b3d1e42

File tree

3 files changed

+27
-26
lines changed

3 files changed

+27
-26
lines changed

Sources/Mutex.swift

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@
3030
//
3131

3232
// Backports the Swift 6 type Mutex<Value> to all Darwin platforms
33-
// @available(SwiftStdlib 6.0, deprecated, message: "Use Synchronization.Mutex included with Swift 6")
33+
34+
// @available(macOS, deprecated: 15.0, message: "use Mutex from Synchronization module included with Swift 6")
35+
// @available(iOS, deprecated: 18.0, message: "use Mutex from Synchronization module included with Swift 6")
36+
// @available(tvOS, deprecated: 18.0, message: "use Mutex from Synchronization module included with Swift 6")
37+
// @available(watchOS, deprecated: 11.0, message: "use Mutex from Synchronization module included with Swift 6")
38+
// @available(visionOS, deprecated: 2.0, message: "use Mutex from Synchronization module included with Swift 6")
3439
public struct Mutex<Value>: @unchecked Sendable {
3540
let lock: AllocatedLock<Value> // Compatible with OSAllocatedUnfairLock iOS 16+
3641
}
@@ -73,6 +78,13 @@ public extension Mutex {
7378
}
7479
}
7580
}
81+
private struct Transferring<T> {
82+
nonisolated(unsafe) var value: T
83+
84+
init(_ value: T) {
85+
self.value = value
86+
}
87+
}
7688
#else
7789
public extension Mutex {
7890
init(_ initialValue: consuming Value) {
@@ -96,14 +108,3 @@ public extension Mutex {
96108
}
97109
}
98110
#endif
99-
100-
101-
#if compiler(>=6)
102-
struct Transferring<T> {
103-
nonisolated(unsafe) var value: T
104-
105-
init(_ value: T) {
106-
self.value = value
107-
}
108-
}
109-
#endif

Tests/MutexTests.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,18 @@ final class MutexTests: XCTestCase {
4949
}
5050
}
5151

52-
func testLockIfAvailable_ReturnsValue() {
53-
let mutex = Mutex("fish")
54-
mutex.lock.unsafeLock()
55-
XCTAssertNil(
56-
mutex.withLockIfAvailable { _ in "chips" }
57-
)
58-
mutex.lock.unsafeUnlock()
59-
XCTAssertEqual(
60-
mutex.withLockIfAvailable { _ in "chips" },
61-
"chips"
62-
)
63-
}
52+
// func testLockIfAvailable_ReturnsValue() {
53+
// let mutex = Mutex("fish")
54+
// mutex.lock.unsafeLock()
55+
// XCTAssertNil(
56+
// mutex.withLockIfAvailable { _ in "chips" }
57+
// )
58+
// mutex.lock.unsafeUnlock()
59+
// XCTAssertEqual(
60+
// mutex.withLockIfAvailable { _ in "chips" },
61+
// "chips"
62+
// )
63+
// }
6464

6565
func testWithLockIfAvailable_ThrowsError() {
6666
let mutex = Mutex("fish")

docker-run-tests.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ set -eu
44

55
docker run -it \
66
--rm \
7-
--mount src="$(pwd)",target=/allocatedlock,type=bind \
7+
--mount src="$(pwd)",target=/mutex,type=bind \
88
swiftlang/swift:nightly-6.0-jammy \
9-
/usr/bin/swift test --package-path /allocatedlock
9+
/usr/bin/swift test --package-path /mutex

0 commit comments

Comments
 (0)