eliminate ptable. ptable.lock -> pid_lock.

This commit is contained in:
Robert Morris 2019-07-07 15:20:13 -04:00
parent 4ce3a5fa21
commit db72f3108f

View file

@ -6,16 +6,15 @@
#include "proc.h"
#include "defs.h"
struct {
struct spinlock lock;
struct proc proc[NPROC];
} ptable;
struct proc proc[NPROC];
struct cpu cpus[NCPU];
struct proc *initproc;
struct spinlock pid_lock;
int nextpid = 1;
extern void forkret(void);
// for returning out of the kernel
@ -30,8 +29,8 @@ procinit(void)
{
struct proc *p;
initlock(&ptable.lock, "ptable");
for(p = ptable.proc; p < &ptable.proc[NPROC]; p++)
initlock(&pid_lock, "nextpid");
for(p = proc; p < &proc[NPROC]; p++)
initlock(&p->lock, "proc");
}
@ -68,9 +67,9 @@ int
allocpid() {
int pid;
acquire(&ptable.lock);
acquire(&pid_lock);
pid = nextpid++;
release(&ptable.lock);
release(&pid_lock);
return pid;
}
@ -85,7 +84,7 @@ allocproc(void)
{
struct proc *p;
for(p = ptable.proc; p < &ptable.proc[NPROC]; p++) {
for(p = proc; p < &proc[NPROC]; p++) {
acquire(&p->lock);
if(p->state == UNUSED) {
goto found;
@ -297,7 +296,7 @@ reparent(struct proc *p, struct proc *parent) {
struct proc *pp;
int child_of_init = (p->parent == initproc);
for(pp = ptable.proc; pp < &ptable.proc[NPROC]; pp++){
for(pp = proc; pp < &proc[NPROC]; pp++){
if (pp != p && pp != parent) {
acquire(&pp->lock);
if(pp->parent == p){
@ -375,7 +374,7 @@ wait(void)
for(;;){
// Scan through table looking for exited children.
havekids = 0;
for(np = ptable.proc; np < &ptable.proc[NPROC]; np++){
for(np = proc; np < &proc[NPROC]; np++){
if(np->parent != p)
continue;
acquire(&np->lock);
@ -421,7 +420,7 @@ scheduler(void)
// Enable interrupts on this processor.
intr_on();
for(p = ptable.proc; p < &ptable.proc[NPROC]; p++) {
for(p = proc; p < &proc[NPROC]; p++) {
acquire(&p->lock);
if(p->state == RUNNABLE) {
// Switch to chosen process. It is the process's job
@ -557,7 +556,7 @@ wakeup(void *chan)
{
struct proc *p;
for(p = ptable.proc; p < &ptable.proc[NPROC]; p++) {
for(p = proc; p < &proc[NPROC]; p++) {
acquire(&p->lock);
if(p->state == SLEEPING && p->chan == chan) {
p->state = RUNNABLE;
@ -574,7 +573,7 @@ kill(int pid)
{
struct proc *p;
for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
for(p = proc; p < &proc[NPROC]; p++){
if(p->pid == pid){
acquire(&p->lock);
if(p->pid != pid)
@ -637,7 +636,7 @@ procdump(void)
struct proc *p;
char *state;
for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
for(p = proc; p < &proc[NPROC]; p++){
if(p->state == UNUSED)
continue;
if(p->state >= 0 && p->state < NELEM(states) && states[p->state])