Created
January 26, 2015 19:54
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