proc allocation tweaks

上级 1e427f09
......@@ -167,7 +167,6 @@ int piperead(struct pipe*, char*, int);
int pipewrite(struct pipe*, char*, int);
// proc.c
struct proc* allocproc(void);
struct proc* copyproc(struct proc*);
void finishproc(struct proc*);
void exit(void);
......
......@@ -80,17 +80,19 @@ struct proc : public rcu_freed {
LIST_ENTRY(proc) cv_sleep; // Linked list of processes sleeping on a cv
u64 user_fs_;
proc(int npid);
~proc(void);
virtual void do_gc(void) { delete this; }
NEW_DELETE_OPS(proc)
void set_state(enum procstate s);
enum procstate get_state(void) const { return state_; }
int set_cpu_pin(int cpu);
static proc* alloc();
private:
proc(int npid);
~proc(void);
proc& operator=(const proc&);
proc(const proc& x);
NEW_DELETE_OPS(proc);
enum procstate state_; // Process state
};
......@@ -108,7 +108,7 @@ idleloop(void)
// If we don't have an heir, try to allocate one
if (idlem->heir == nullptr) {
struct proc *p;
p = allocproc();
p = proc::alloc();
if (p == nullptr)
break;
snprintf(p->name, sizeof(p->name), "idleh_%u", mycpu()->id);
......@@ -135,9 +135,9 @@ idleloop(void)
void
initidle(void)
{
struct proc *p = allocproc();
struct proc *p = proc::alloc();
if (!p)
panic("initidle allocproc");
panic("initidle proc::alloc");
SLIST_INIT(&idlem[cpunum()].zombies);
initlock(&idlem[cpunum()].lock, "idle_lock", LOCKSTAT_IDLE);
......
......@@ -198,18 +198,15 @@ freeproc(struct proc *p)
gc_delayed(p);
}
// Look in the process table for an UNUSED proc.
// If found, change state to EMBRYO and initialize
// state required to run in the kernel.
// Otherwise return 0.
struct proc*
allocproc(void)
proc*
proc::alloc(void)
{
struct proc *p;
char *sp;
proc* p;
p = new proc(xnspid->allockey());
if (p == 0) return 0;
if (p == nullptr)
return nullptr;
p->cpuid = mycpu()->id;
initprocgc(p);
......@@ -344,7 +341,7 @@ fork(int flags)
// cprintf("%d: fork\n", myproc()->pid);
// Allocate process.
if((np = allocproc()) == 0)
if((np = proc::alloc()) == 0)
return -1;
if(flags == 0) {
......@@ -466,7 +463,7 @@ threadalloc(void (*fn)(void *), void *arg)
{
struct proc *p;
p = allocproc();
p = proc::alloc();
if (p == nullptr)
return 0;
......
......@@ -20,7 +20,7 @@ inituser(void)
extern u8 _initcode_start[];
extern u64 _initcode_size;
p = allocproc();
p = proc::alloc();
p->ftable = new filetable();
if (p->ftable == nullptr)
panic("userinit: new filetable");
......
......@@ -264,7 +264,7 @@ uwq::allocworker(void)
if (uentry == 0)
return nullptr;
proc* p = allocproc();
proc* p = proc::alloc();
if (p == nullptr)
return nullptr;
safestrcpy(p->name, "uwq_worker", sizeof(p->name));
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论