-
-
Save zyuanming/dae2aced0b1d5da080a8e017f1cfc1bb to your computer and use it in GitHub Desktop.
Locks
This file contains hidden or 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
| internal final class SpinLock { | |
| private let lock = NSLock() | |
| func sync<T>(action: () -> T) -> T { | |
| lock.lock() | |
| defer { lock.unlock() } | |
| return action() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment