Files
swift-composable-architectu…/Sources/ComposableArchitecture/Internal/Locking.swift
Stephen Celis d2d994dff5 Cancellation Fixes (#169)
* Failing test when reusing cancellation id.

* wip

* Clean up

* update test

* Update Tests/ComposableArchitectureTests/TimerTests.swift

* move methods around

* wip

* more

* wip

Co-authored-by: Brandon Williams <mbw234@gmail.com>
2020-06-04 13:38:20 -04:00

20 lines
419 B
Swift

import Foundation
extension UnsafeMutablePointer where Pointee == os_unfair_lock_s {
@inlinable @discardableResult
func sync<R>(_ work: () -> R) -> R {
os_unfair_lock_lock(self)
defer { os_unfair_lock_unlock(self) }
return work()
}
}
extension NSRecursiveLock {
@inlinable @discardableResult
func sync<R>(work: () -> R) -> R {
self.lock()
defer { self.unlock() }
return work()
}
}