Make ThreadSpinLock large to prevent false sharing

This fixes #3161
This commit is contained in:
Markus Pilman 2020-07-13 11:38:00 -06:00
parent dfca94d00f
commit bf07964fea
1 changed files with 8 additions and 0 deletions

View File

@ -23,6 +23,7 @@
#pragma once
#include <atomic>
#include <array>
#include "flow/Error.h"
#include "flow/Trace.h"
@ -44,6 +45,10 @@
#include <drd.h>
#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<uint8_t, CACHE_LINE_SIZE - sizeof(isLocked)> padding;
};
class ThreadSpinLockHolder {