A dubious percpu class

上级 b6be0a0f
struct pad {
__padout__;
} __mpalign__;
template <typename T>
struct percpu {
int myid() {
return mycpu()->id;
}
const T* operator->() const {
return cpu(myid());
}
T* operator->() {
return cpu(myid());
}
T& operator[](int id) {
return *cpu(id);
}
const T& operator[](int id) const {
return *cpu(id);
}
T* cpu(int id) {
return &v_[id];
}
T v_[NCPU] __mpalign__;
};
......@@ -6,16 +6,17 @@
#include "proc.hh"
#include "cpu.hh"
#include "sched.hh"
#include "percpu.hh"
// XXX(sbw) these should be padded out
struct idle {
struct idle : public pad {
struct proc *cur;
struct proc *heir;
SLIST_HEAD(zombies, proc) zombies;
struct spinlock lock;
};
struct idle idlem[NCPU] __mpalign__;
static percpu<idle> idlem;
struct proc * idlep[NCPU] __mpalign__;
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论