-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathpercpu.hh
More file actions
52 lines (43 loc) · 1.11 KB
/
Copy pathpercpu.hh
File metadata and controls
52 lines (43 loc) · 1.11 KB
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
48
49
50
51
52
#pragma once
#include "cpu.hh"
#include "spercpu.hh"
template <typename T, critical_mask CM = NO_SCHED>
struct percpu {
constexpr percpu() = default;
percpu(const percpu &o) = delete;
percpu(percpu &&o) = delete;
percpu &operator=(const percpu &o) = delete;
// Ignore the safety policy and return the value of this variable
// for the CPU that is current at some instant between entering and
// returning from this method.
T* get_unchecked() const {
return cpu(myid());
}
T* operator->() const {
#if DEBUG
check_critical(CM);
#endif
return cpu(myid());
}
T& operator*() const {
#if DEBUG
check_critical(CM);
#endif
return *cpu(myid());
}
T& operator[](int id) const {
return *cpu(id);
}
private:
T* cpu(int id) const {
return &pad_[id].v_;
}
// percpu acts like a T* const, but since it's actually storing the
// data directly, we have to strip the const-ness away from the data
// being stored. This lets const members return non-const pointers
// to this data, just like a T* const.
mutable struct {
T v_ __mpalign__;
__padout__;
} pad_[NCPU];
};