diff --git a/flow/ThreadPrimitives.h b/flow/ThreadPrimitives.h index 6e43b8f1ab..35d3f4c287 100644 --- a/flow/ThreadPrimitives.h +++ b/flow/ThreadPrimitives.h @@ -23,6 +23,7 @@ #pragma once #include +#include #include "flow/Error.h" #include "flow/Trace.h" @@ -44,6 +45,10 @@ #include #endif +// TODO: We should make this dependent on the CPU. Maybe cmake +// can set this variable properly? +constexpr size_t CACHE_LINE_SIZE = 64; + class ThreadSpinLock { public: // #ifdef _WIN32 @@ -83,6 +88,9 @@ private: ThreadSpinLock(const ThreadSpinLock&); void operator=(const ThreadSpinLock&); std::atomic_flag isLocked = ATOMIC_FLAG_INIT; + // We want a spin lock to occupy a cache line in order to + // prevent false sharing. + std::array padding; }; class ThreadSpinLockHolder {