提交 2743888d 创建 作者: Austin Clements's avatar Austin Clements

Redesign percpu<> const-ness and general percpu cleanup

percpu acts like a T* const, so a const percpu should (also) be like a T* const, *not* like a const T*, which is what the code previously did (remember, C types are inside-out! except when they aren't). This, for example, makes it sane to pass a const percpu reference. This also makes percpu non-copyable and non-assignable and makes stuff private.
上级 23af7cf9
......@@ -4,31 +4,38 @@ extern int mycpuid(void);
template <typename T>
struct percpu {
const T* operator->() const {
percpu() = default;
percpu(const percpu &o) = delete;
percpu(percpu &&o) = delete;
percpu &operator=(const percpu &o) = delete;
T* get() const {
return cpu(mycpuid());
}
T* operator->() {
T* operator->() const {
return cpu(mycpuid());
}
T& operator*() {
T& operator*() const {
return *cpu(mycpuid());
}
T& operator[](int id) {
return *cpu(id);
}
const T& operator[](int id) const {
T& operator[](int id) const {
return *cpu(id);
}
T* cpu(int id) {
private:
T* cpu(int id) const {
return &pad_[id].v_;
}
struct {
// 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];
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论