Created
January 26, 2015 19:54
-
-
Save blasten/bab4e3eec4a0eea8515d to your computer and use it in GitHub Desktop.
Grabs a lock and ensures mutual exclusion in swift
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
/** | |
* 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