Skip to content

Commit

Permalink
Merge pull request #861 from ReactiveCocoa/michael/swift57-check-for-…
Browse files Browse the repository at this point in the history
…osallocatedunfairlock-2
  • Loading branch information
mluisbrown committed Nov 27, 2022
2 parents 0bad323 + 8595bb8 commit 80216da
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
44 changes: 25 additions & 19 deletions Sources/Atomic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,29 +137,31 @@ internal class Lock: LockProtocol {
#endif

#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
@available(iOS 16.0, *)
@available(macOS 13.0, *)
@available(tvOS 16.0, *)
@available(watchOS 9.0, *)
internal final class AllocatedUnfairLock: Lock {
private let _lock = OSAllocatedUnfairLock()

override init() {
super.init()
}
#if swift(>=5.7)
@available(iOS 16.0, *)
@available(macOS 13.0, *)
@available(tvOS 16.0, *)
@available(watchOS 9.0, *)
internal final class AllocatedUnfairLock: Lock {
private let _lock = OSAllocatedUnfairLock()

override init() {
super.init()
}

override func lock() {
_lock.lock()
}
override func lock() {
_lock.lock()
}

override func unlock() {
_lock.unlock()
}
override func unlock() {
_lock.unlock()
}

override func `try`() -> Bool {
_lock.lockIfAvailable()
override func `try`() -> Bool {
_lock.lockIfAvailable()
}
}
}
#endif
#endif

internal final class PthreadLock: Lock {
Expand Down Expand Up @@ -221,11 +223,15 @@ internal class Lock: LockProtocol {

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

return AllocatedUnfairLock() as! Self
#else
return UnfairLock() as! Self
#endif
#else
return PthreadLock() as! Self
#endif
Expand Down
2 changes: 1 addition & 1 deletion Sources/Scheduler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ public final class TestScheduler: DateScheduler {
while lock.sync({ _currentDate }) <= newDate {
await Task.megaYield()

let `return` = lock.sync {
let `return`: Bool = lock.sync { () -> Bool in
guard
let next = scheduledActions.first,
newDate >= next.date
Expand Down

0 comments on commit 80216da

Please sign in to comment.