proc allocation tweaks

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