Created
June 18, 2014 10:47
-
-
Save ykst/20d296be644f87964d0b to your computer and use it in GitHub Desktop.
iOSでスピンロック ref: http://qiita.com/ykst/items/abab52d496b4ca37a82a
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
#include <libkern/OSAtomic.h> | |
static volatile OSSpinLock lock = OS_SPINLOCK_INIT; | |
void spinlock_lock() | |
{ | |
OSSpinLockLock(&lock); | |
} | |
void spinlock_unlock() | |
{ | |
OSSpinLockUnlock(&lock); | |
} |
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
#define SPINLOCK(lock) for (int ___do = ({ OSSpinLockLock(&(lock)); 1; }); ___do || ({ OSSpinLockUnlock(&(lock)); 0; }); ___do = 0) | |
... | |
SPINLOCK(a_lock) { | |
do_something(); | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment