Skip to content

Instantly share code, notes, and snippets.

@blasten
Created January 26, 2015 19:54
Show Gist options
  • Save blasten/bab4e3eec4a0eea8515d to your computer and use it in GitHub Desktop.
Save blasten/bab4e3eec4a0eea8515d to your computer and use it in GitHub Desktop.
Grabs a lock and ensures mutual exclusion in swift
/**
* Grabs a lock and ensures mutual exclusion while calling `closure`
* Example:
* synced(self) {
* // Code
* }
*/
func synced(lock: AnyObject, closure: () -> ()) {
objc_sync_enter(lock)
closure()
objc_sync_exit(lock)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment