Skip to content

Instantly share code, notes, and snippets.

@comfly
Created April 14, 2016 09:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save comfly/15ced99cb4f2a5e1809a1c0c7adfe8b3 to your computer and use it in GitHub Desktop.
Save comfly/15ced99cb4f2a5e1809a1c0c7adfe8b3 to your computer and use it in GitHub Desktop.
public final class SpinLock {
private var lock: OSSpinLock = OS_SPINLOCK_INIT
public func locked<A>(@noescape f: () throws -> A) rethrows -> A {
OSSpinLockLock(&lock)
defer { OSSpinLockUnlock(&lock) }
return try f()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment