Skip to content

Commit 80216da

Browse files
authored
Merge pull request #861 from ReactiveCocoa/michael/swift57-check-for-osallocatedunfairlock-2
2 parents 0bad323 + 8595bb8 commit 80216da

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

Sources/Atomic.swift

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -137,29 +137,31 @@ internal class Lock: LockProtocol {
137137
#endif
138138

139139
#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
140-
@available(iOS 16.0, *)
141-
@available(macOS 13.0, *)
142-
@available(tvOS 16.0, *)
143-
@available(watchOS 9.0, *)
144-
internal final class AllocatedUnfairLock: Lock {
145-
private let _lock = OSAllocatedUnfairLock()
146-
147-
override init() {
148-
super.init()
149-
}
140+
#if swift(>=5.7)
141+
@available(iOS 16.0, *)
142+
@available(macOS 13.0, *)
143+
@available(tvOS 16.0, *)
144+
@available(watchOS 9.0, *)
145+
internal final class AllocatedUnfairLock: Lock {
146+
private let _lock = OSAllocatedUnfairLock()
147+
148+
override init() {
149+
super.init()
150+
}
150151

151-
override func lock() {
152-
_lock.lock()
153-
}
152+
override func lock() {
153+
_lock.lock()
154+
}
154155

155-
override func unlock() {
156-
_lock.unlock()
157-
}
156+
override func unlock() {
157+
_lock.unlock()
158+
}
158159

159-
override func `try`() -> Bool {
160-
_lock.lockIfAvailable()
160+
override func `try`() -> Bool {
161+
_lock.lockIfAvailable()
162+
}
161163
}
162-
}
164+
#endif
163165
#endif
164166

165167
internal final class PthreadLock: Lock {
@@ -221,11 +223,15 @@ internal class Lock: LockProtocol {
221223

222224
static func make() -> Self {
223225
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
226+
#if swift(>=5.7)
224227
guard #available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) else {
225228
return UnfairLock() as! Self
226229
}
227230

228231
return AllocatedUnfairLock() as! Self
232+
#else
233+
return UnfairLock() as! Self
234+
#endif
229235
#else
230236
return PthreadLock() as! Self
231237
#endif

Sources/Scheduler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ public final class TestScheduler: DateScheduler {
769769
while lock.sync({ _currentDate }) <= newDate {
770770
await Task.megaYield()
771771

772-
let `return` = lock.sync {
772+
let `return`: Bool = lock.sync { () -> Bool in
773773
guard
774774
let next = scheduledActions.first,
775775
newDate >= next.date

0 commit comments

Comments
 (0)