Files
swift-composable-architectu…/Sources/ComposableArchitecture/Internal/Locking.swift
2022-10-11 13:10:16 -04:00

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()
}
}