Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update handling of os_unfair_lock to manage the buffer. #2836

Merged
merged 1 commit into from Jun 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 13 additions & 3 deletions Source/Protector.swift
Expand Up @@ -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.
Expand Down