File tree Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Original file line number Diff line number Diff line change 5
5
6
6
#include < stddef.h>
7
7
8
+ constexpr int DEFAULT_CACHE_LINE_SIZE = 64 ;
9
+
8
10
static inline long long atomicInc (volatile long long &var,
9
11
long long increment = 1 ) {
10
12
return __sync_fetch_and_add (&var, increment);
Original file line number Diff line number Diff line change 21
21
22
22
// Cannot use regular mutexes inside signal handler.
23
23
// This lock is based on CAS busy loop. GCC atomic builtins imply full barrier.
24
- class SpinLock {
24
+ class alignas (DEFAULT_CACHE_LINE_SIZE) SpinLock {
25
25
private:
26
26
// 0 - unlocked
27
27
// 1 - exclusive lock
28
28
// <0 - shared lock
29
29
volatile int _lock;
30
-
30
+ char _padding[DEFAULT_CACHE_LINE_SIZE - sizeof (_lock)];
31
31
public:
32
- constexpr SpinLock (int initial_state = 0 ) : _lock(initial_state) {}
32
+ constexpr SpinLock (int initial_state = 0 ) : _lock (initial_state), _padding () {
33
+ static_assert (sizeof (SpinLock) == DEFAULT_CACHE_LINE_SIZE);
34
+ }
33
35
34
36
void reset () { _lock = 0 ; }
35
37
You can’t perform that action at this time.
0 commit comments