Created
February 8, 2014 20:28
-
-
Save CodaFi/8889704 to your computer and use it in GitHub Desktop.
A macro for automatically locking and unlocking critical sections of code with OSSpinLocks.
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
/** | |
* Usage: | |
* | |
* static OSSpinlock lock; | |
* | |
* @critical_section(lock, ^{ | |
* //Synchronized Section | |
* }); | |
* | |
*/ | |
static inline void __nui_cleanup(volatile OSSpinLock **lock) { | |
OSSpinLockUnlock(*lock); | |
} | |
#ifndef critical_section | |
#define critical_section(LOCK, BLOCK) \ | |
autoreleasepool {} \ | |
do {\ | |
volatile OSSpinLock *__nui_local_lock __attribute__ ((__cleanup__(__nui_cleanup))) = &LOCK; \ | |
OSSpinLockLock(__nui_local_lock); \ | |
BLOCK(); \ | |
} while (0) | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment