未验证 提交 1b89a57c 编写于 作者: J Jon Shier 提交者: GitHub

Update handling of os_unfair_lock to manage the buffer. (#2836)

As recommended by Apple at WWDC, using os_unfair_lock by reference will lead to a crash rate of up to 1%.
上级 a516974f
......@@ -28,14 +28,24 @@ import Foundation
/// An `os_unfair_lock` wrapper.
final class UnfairLock {
private var unfairLock = os_unfair_lock()
private let unfairLock: os_unfair_lock_t
init() {
unfairLock = .allocate(capacity: 1)
unfairLock.initialize(to: os_unfair_lock())
}
deinit {
unfairLock.deinitialize(count: 1)
unfairLock.deallocate()
}
fileprivate func lock() {
os_unfair_lock_lock(&unfairLock)
os_unfair_lock_lock(unfairLock)
}
fileprivate func unlock() {
os_unfair_lock_unlock(&unfairLock)
os_unfair_lock_unlock(unfairLock)
}
/// Executes a closure returning a value while acquiring the lock.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册