This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Cocoa | |
extension NSGestureRecognizer { | |
private class CallbackWrapper { | |
let callback: NSGestureRecognizer.Callback | |
weak var gestureRecognizer: NSGestureRecognizer? | |
init(callback:@escaping NSGestureRecognizer.Callback) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@inline(__always) | |
func synchronized<T>(_ lock: AnyObject, _ body: () throws -> T) rethrows -> T { | |
objc_sync_enter(lock) | |
defer { objc_sync_exit(lock) } | |
return try body() | |
} | |
// example of usage | |
synchronized (self) {[weak self] in | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@propertyWrapper | |
struct Atomic<Value> { | |
var lock = os_unfair_lock_s() | |
var _value: Value | |
init(wrappedValue value: Value) { | |
_value = value | |
} | |