Skip to content
Snippets Groups Projects
Commit dc64f98b authored by Fache Charles's avatar Fache Charles
Browse files

fixed a few deadlocks some still subsist for mystical reasons

parent e4e40822
No related branches found
Tags tp1-act-3-3
No related merge requests found
......@@ -141,7 +141,7 @@ static struct proc*
allocproc(void)
{
struct proc *p;
acquire(&prio_lock);
for(p = proc; p < &proc[NPROC]; p++) {
acquire(&p->lock);
if(p->state == UNUSED) {
......@@ -271,10 +271,8 @@ userinit(void)
p->cwd = namei("/");
p->state = RUNNABLE;
release(&p->lock);
p->priority = DEF_PRIO;
acquire(&prio_lock);
acquire(&p->lock);
insert_into_prio_queue(p);
release(&p->lock);
release(&prio_lock);
......@@ -318,6 +316,7 @@ fork(void)
if(uvmcopy(p->pagetable, np->pagetable, p->sz) < 0){
freeproc(np);
release(&np->lock);
release(&prio_lock);
return -1;
}
np->sz = p->sz;
......@@ -344,11 +343,8 @@ fork(void)
np->state = RUNNABLE;
release(&np->lock);
acquire(&prio_lock);
acquire(&np->lock);
insert_into_prio_queue(np);
release(&np->lock);
release(&prio_lock);
......@@ -471,6 +467,7 @@ wait(uint64 addr)
// np->parent can't change between the check and the acquire()
// because only the parent changes it, and we're the parent.
// acquire(&prio_lock);
acquire(&prio_lock);
acquire(&np->lock);
havekids = 1;
if(np->state == ZOMBIE){
......@@ -479,13 +476,11 @@ wait(uint64 addr)
if(addr != 0 && copyout(p->pagetable, addr, (char *)&np->xstate,
sizeof(np->xstate)) < 0) {
release(&np->lock);
release(&prio_lock);
release(&p->lock);
return -1;
}
release(&np->lock);
acquire(&prio_lock);
acquire(&np->lock);
remove_from_prio_queue(np);
freeproc(np);
release(&np->lock);
......@@ -495,6 +490,7 @@ wait(uint64 addr)
return pid;
}
release(&np->lock);
release(&prio_lock);
}
}
......@@ -513,10 +509,11 @@ wait(uint64 addr)
// returns it, returns 0 if no runnable process is found.
struct proc*
pick_highest_priority_runnable_proc() {
for (int i = 0; i < NPRIO; i++) {
struct list_proc* list = prio[i];
acquire(&prio_lock);
struct list_proc* observed = list;
struct list_proc* observed;
acquire(&prio_lock);
for (int prio_index = 0; prio_index < NPRIO; prio_index++) {
observed = prio[prio_index];
while(observed) {
struct proc* p = observed->p;
......@@ -528,8 +525,8 @@ pick_highest_priority_runnable_proc() {
observed = observed->next;
}
release(&prio_lock);
}
release(&prio_lock);
return 0;
// for (struct list_proc* lp = prio[0]; lp < prio[NPRIO]; lp++) { // go through all priority lists
......@@ -584,11 +581,11 @@ scheduler(void)
remove_from_prio_queue(p);
insert_into_prio_queue(p);
c->intena = 0;
release(&prio_lock);
swtch(&c->scheduler, &p->context);
c->proc = 0;
c->intena = 0;
release(&p->lock);
} else {
......@@ -825,13 +822,10 @@ void priodump(void){
// the provided pid is valid, 0 otherwise
int
nice(int pid, int priority) {
acquire(&prio_lock);
for(struct proc* p = proc; p < &proc[NPROC]; p++) {
acquire(&p->lock);
if (p->pid == pid) {
release(&p->lock);
acquire(&prio_lock);
acquire(&p->lock);
remove_from_prio_queue(p);
......@@ -846,5 +840,6 @@ nice(int pid, int priority) {
}
release(&p->lock);
}
release(&prio_lock);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment