mirror of
https://github.com/pointfreeco/swift-composable-architecture.git
synced 2025-12-20 09:11:33 +01:00
20 lines
443 B
Swift
20 lines
443 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
|
|
@_spi(Internals) public func sync<R>(work: () -> R) -> R {
|
|
self.lock()
|
|
defer { self.unlock() }
|
|
return work()
|
|
}
|
|
}
|