Skip to content

Instantly share code, notes, and snippets.

@leiless
Created November 2, 2018 07:00
Show Gist options
  • Save leiless/cfff539426e7d9f4f2f3e73f22902d6b to your computer and use it in GitHub Desktop.
Save leiless/cfff539426e7d9f4f2f3e73f22902d6b to your computer and use it in GitHub Desktop.
/*
* Created 181102
*/
#include <libkern/OSAtomicDeprecated.h>
static volatile int __spin;
#define spin_lock() while (!OSAtomicCompareAndSwapInt(0, 1, &__spin)) continue
#define spin_unlock() do { \
bool ok = OSAtomicCompareAndSwapInt(1, 0, &__spin); \
NSCAssert(ok == 1, @"spin_unlock() failure"); \
} while (0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment