Skip to content

Instantly share code, notes, and snippets.

@blasten blasten/synced.swift
Created Jan 26, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.