blob: e7086f2da2689c37af57067318cc37d9353a914f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
#pragma once
extern "C" {
#include "hack.h"
#include "spinlock.h"
}
#define SPINLOCK_INITIALIZER { _SPINLOCK_INITIALIZER }
struct TCMalloc_SpinLock {
volatile spinlock_t private_lockword_;
inline void Init() noexcept {
private_lockword_ = _SPINLOCK_INITIALIZER;
}
inline void Finalize() noexcept {
}
inline void Lock() noexcept {
_SPINLOCK(&private_lockword_);
}
inline void Unlock() noexcept {
_SPINUNLOCK(&private_lockword_);
}
};
class TCMalloc_SpinLockHolder {
private:
TCMalloc_SpinLock* lock_;
public:
inline explicit TCMalloc_SpinLockHolder(TCMalloc_SpinLock* l)
: lock_(l)
{
l->Lock();
}
inline ~TCMalloc_SpinLockHolder() {
lock_->Unlock();
}
};
// Short-hands for convenient use by tcmalloc.cc
typedef TCMalloc_SpinLock SpinLock;
typedef TCMalloc_SpinLockHolder SpinLockHolder;
|