Skip to content

Instantly share code, notes, and snippets.

@ifknot
Created January 1, 2018 00:46
Show Gist options
  • Save ifknot/db359c78841cc9ca694a6a5f28e9ddfd to your computer and use it in GitHub Desktop.
Save ifknot/db359c78841cc9ca694a6a5f28e9ddfd to your computer and use it in GitHub Desktop.
MCS Lock
#ifndef CPU_RELAX_H
#define CPU_RELAX_H
#include <intrin.h>
namespace sync {
inline static void cpu_relax() {
#if (COMPILER == MVCC)
_mm_pause();
#elif (COMPILER == GCC || COMPILER == LLVM)
asm volatile("pause\n": : :"memory");
#endif
}
}
#endif // CPU_RELAX_H
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment