mirror of
https://github.com/apple/foundationdb.git
synced 2025-06-01 10:45:56 +08:00
parent
dfca94d00f
commit
bf07964fea
@ -23,6 +23,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <array>
|
||||||
|
|
||||||
#include "flow/Error.h"
|
#include "flow/Error.h"
|
||||||
#include "flow/Trace.h"
|
#include "flow/Trace.h"
|
||||||
@ -44,6 +45,10 @@
|
|||||||
#include <drd.h>
|
#include <drd.h>
|
||||||
#endif
|
#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 {
|
class ThreadSpinLock {
|
||||||
public:
|
public:
|
||||||
// #ifdef _WIN32
|
// #ifdef _WIN32
|
||||||
@ -83,6 +88,9 @@ private:
|
|||||||
ThreadSpinLock(const ThreadSpinLock&);
|
ThreadSpinLock(const ThreadSpinLock&);
|
||||||
void operator=(const ThreadSpinLock&);
|
void operator=(const ThreadSpinLock&);
|
||||||
std::atomic_flag isLocked = ATOMIC_FLAG_INIT;
|
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 {
|
class ThreadSpinLockHolder {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user