Skip to content

Instantly share code, notes, and snippets.

@ykst
Created June 18, 2014 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ykst/20d296be644f87964d0b to your computer and use it in GitHub Desktop.
Save ykst/20d296be644f87964d0b to your computer and use it in GitHub Desktop.
iOSでスピンロック ref: http://qiita.com/ykst/items/abab52d496b4ca37a82a
#include <libkern/OSAtomic.h>
static volatile OSSpinLock lock = OS_SPINLOCK_INIT;
void spinlock_lock()
{
OSSpinLockLock(&lock);
}
void spinlock_unlock()
{
OSSpinLockUnlock(&lock);
}
#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