Skip to content

Commit 662693e

Browse files
committed
More refactorings
1 parent bb5586a commit 662693e

File tree

5 files changed

+717
-894
lines changed

5 files changed

+717
-894
lines changed

Package.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ let package = Package(
2020
targets: [
2121
.target(
2222
name: "AsyncAlgorithms",
23-
dependencies: [.product(name: "Collections", package: "swift-collections")],
23+
dependencies: [
24+
.product(name: "DequeModule", package: "swift-collections"),
25+
.product(name: "OrderedCollections", package: "swift-collections"),
26+
],
2427
swiftSettings: [
2528
.enableExperimentalFeature("StrictConcurrency=complete"),
2629
]

Sources/AsyncAlgorithms/Locking.swift

+10-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import WinSDK
1818
#endif
1919

2020
@usableFromInline
21-
internal struct Lock {
21+
internal class Lock {
2222
#if canImport(Darwin)
2323
@usableFromInline
2424
typealias Primitive = os_unfair_lock
@@ -35,12 +35,17 @@ internal struct Lock {
3535

3636
@usableFromInline
3737
typealias PlatformLock = UnsafeMutablePointer<Primitive>
38+
@usableFromInline
3839
let platformLock: PlatformLock
3940

4041
private init(_ platformLock: PlatformLock) {
4142
self.platformLock = platformLock
4243
}
43-
44+
45+
deinit {
46+
self.deinitialize()
47+
}
48+
4449
fileprivate static func initialize(_ platformLock: PlatformLock) {
4550
#if canImport(Darwin)
4651
platformLock.initialize(to: os_unfair_lock())
@@ -93,10 +98,12 @@ internal struct Lock {
9398
Lock.deinitialize(platformLock)
9499
}
95100

101+
@inlinable
96102
func lock() {
97103
Lock.lock(platformLock)
98104
}
99105

106+
@inlinable
100107
func unlock() {
101108
Lock.unlock(platformLock)
102109
}
@@ -109,6 +116,7 @@ internal struct Lock {
109116
///
110117
/// - Parameter body: The block to execute while holding the lock.
111118
/// - Returns: The value returned by the block.
119+
@inlinable
112120
func withLock<T>(_ body: () throws -> T) rethrows -> T {
113121
self.lock()
114122
defer {

0 commit comments

Comments
 (0)