void handleLeftDoubleClick() { WindowQueue *pwindowQueue; Widget *pwidget; pwindowQueue = getClickedWindowQueue(); if (pwindowQueue) { focusDismiss(); switchuvm(pwindowQueue->proc); pwidget = getClickedWidget(pwindowQueue->window); if (pwidget) { switch (pwidget->type) { case iconView: pwidget->context.iconView->onLeftDoubleClickHandler.triggered = 1; break; default: break; } } } if (proc == 0) switchkvm(); else switchuvm(proc); }
void handleMouseDrag() { if (drag_state == 0) { pwque = getDraggedWindowQueue(); if (pwque) { drag_state = 1; if (pwque != lastWindow && pwque != &windowLine[0]) reorderQueue(pwque); } else drag_state = 2; } else if (drag_state == 1) { switchuvm(pwque->proc); counter = (counter + 1) % 20; if (counter == 0) isdraw = 1; else isdraw = 0; moveWindow(pwque->window, mouse_info.x_position, mouse_info.y_position, down_pos_x, down_pos_y, isdraw); } if (proc == 0) switchkvm(); else switchuvm(proc); }
// Grow current process's memory by n bytes. // Return 0 on success, -1 on failure. int growproc(int n) { uint sz; struct proc *p; sz = proc->sz; if(n > 0){ if((sz = allocuvm(proc->pgdir, sz, sz + n)) == 0) return -1; } else if(n < 0){ if((sz = deallocuvm(proc->pgdir, sz, sz + n)) == 0) return -1; } proc->sz = sz; //other threads int tid = proc->tid; acquire(&ptable.lock); for( p = ptable.proc; p < &ptable.proc[NPROC]; p++) if(p->tid == tid) p->sz = sz; release(&ptable.lock); switchuvm(proc); return 0; }
//PAGEBREAK: 42 // Per-CPU process scheduler. // Each CPU calls scheduler() after setting itself up. // Scheduler never returns. It loops, doing: // - choose a process to run // - swtch to start running that process // - eventually that process transfers control // via swtch back to the scheduler. void scheduler(void) { struct proc *p; for(;;){ // Enable interrupts on this processor. sti(); // Loop over process table looking for process to run. acquire(&ptable.lock); for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ if(p->state != RUNNABLE) continue; // Switch to chosen process. It is the process's job // to release ptable.lock and then reacquire it // before jumping back to us. proc = p; switchuvm(p); p->state = RUNNING; swtch(&cpu->scheduler, proc->context); switchkvm(); // Process is done running for now. // It should have changed its p->state before coming back. proc = 0; } release(&ptable.lock); } }
// Grow current process's memory by n bytes. // Return 0 on success, -1 on failure. /// Need to add locks to this function to make it work with threads! int growproc(int n) { uint sz; sz = proc->sz; if(n > 0){ if((sz = allocuvm(proc->pgdir, sz, sz + n)) == 0) return -1; } else if(n < 0){ if((sz = deallocuvm(proc->pgdir, sz, sz + n)) == 0) return -1; } proc->sz = sz; switchuvm(proc); acquire(&ptable.lock); // Now update the sz variable for all other processes sharing this address space struct proc *p; for(p = ptable.proc; p < &ptable.proc[NPROC]; p++) { if(p->pgdir == proc->pgdir && p != proc) { p->sz = proc->sz; } } release(&ptable.lock); return 0; }
// Grow current process's memory by n bytes. // Return 0 on success, -1 on failure. int growproc(int n) { uint sz; struct proc* p; sz = proc->sz; if(n > 0){ if((sz = allocuvm(proc->pgdir, sz, sz + n)) == 0) return -1; } else if(n < 0){ if((sz = deallocuvm(proc->pgdir, sz, sz + n)) == 0) return -1; } proc->sz = sz; acquire(&ptable.lock); for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ if(p->state == UNUSED || p->pgdir != proc->pgdir) continue; p->sz = sz; } release(&ptable.lock); switchuvm(proc); return 0; }
// Grow current process's memory by n bytes. // Return 0 on success, -1 on failure. int growproc(int n) { uint sz; sz = proc->sz; if(n > 0) { //prevent heap from overwriting our stack int se=proc->se; int page_n = PGROUNDUP(n); int heap_size = PGROUNDUP(proc->sz); if((heap_size + page_n) > (se - PGSIZE)) { //panic("Heap is overwriting stack!"); //just return -1 is sufficient. No need to panic! return -1; } if((sz = allocuvm(proc->pgdir, sz, sz + n)) == 0) return -1; } else if(n < 0) { if((sz = deallocuvm(proc->pgdir, sz, sz + n)) == 0) return -1; } proc->sz = sz; switchuvm(proc); return 0; }
// Grow current process's memory by n bytes. // Return 0 on success, -1 on failure. int growproc(int n) { uint sz; // struct proc *p; sz = proc->sz; acquire(&ptable.lock); // if(proc->thread == 1){ // for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ // if(proc->parent == p || p->parent == proc->parent){ // if(n > 0){ // if((sz = allocuvm(p->pgdir, sz, sz + n)) == 0) // return -1; // }else if(n < 0){ // if((sz = deallocuvm(p->pgdir, sz, sz + n)) == 0) // return -1; // } // } // } // } if(n > 0){ if((sz = allocuvm(proc->pgdir, sz, sz + n)) == 0) return -1; }else if(n < 0){ if((sz = deallocuvm(proc->pgdir, sz, sz + n)) == 0) return -1; } proc->sz = sz; release(&ptable.lock); switchuvm(proc); return 0; }
void scheduler(){ struct proc *p; while(1){ /* set interrupts ??? */ for(p=ptable.proc;p<&ptable.proc[NPROC];p++){ if(p->state!=RUNNABLE){ continue; } /* switch to this process. */ proc=p; switchuvm(p); p->state=RUNNING; swtch(&cpu.scheduler,p->context); /* __asm__ volatile( */ /* "movq %0,%%rsp;" */ /* : */ /* :"r"((char *)(proc->tf) - 8) */ /* : */ /* ); */ /* __asm__ volatile("retq;"); */ } } }
// Grow current process's memory by n bytes. // Return 0 on success, -1 on failure. int growproc(int n) { uint sz; struct proc * p; acquire(&sbrklock); sz = proc->sz; if(n > 0){ if((sz = allocuvm(proc->pgdir, sz, sz + n)) == 0) return -1; } else if(n < 0){ if((sz = deallocuvm(proc->pgdir, sz, sz + n)) == 0) return -1; } acquire(&ptable.lock); for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ if(p->pgdir == proc->pgdir) p->sz = sz; } release(&ptable.lock); switchuvm(proc); release(&sbrklock); return 0; }
// Grow current process's memory by n bytes. // Return 0 on success, -1 on failure. int growproc(int n) { uint sz; sz = proc->sz; uint stack; stack = proc->stack; // cprintf("\n\n\n\nStack %x\t Size: %x\n",(uint)PGROUNDDOWN(stack-PGSIZE),sz); cprintf("Heap needs: [%x] more\t Stack: %x\t Process size: %x\n",n,(uint)PGROUNDDOWN(stack-PGSIZE),sz); if (n > (uint)PGROUNDDOWN(stack-PGSIZE) - sz){ // cprintf("Heap needs: [%x] more\t Stack: %x\t Process size: %x\n",n,(uint)PGROUNDDOWN(stack-PGSIZE),sz); cprintf("Heap growing too much!\n"); // proc->killed=1; return -1; } if(n > 0){ if((sz = allocuvm(proc->pgdir, sz, sz + n)) == 0) return -1; } else if(n < 0){ if((sz = deallocuvm(proc->pgdir, sz, sz + n)) == 0) return -1; } proc->sz = sz; switchuvm(proc); return 0; }
int clone(void(*fcn)(void*), void *arg, void *stack) { int i, pid; struct proc *np; uint * sp; // ALLOCATES A NEW THREAD // // Allocate process. if((np = allocproc()) == 0) return -1; //if a thread calls clone it makes its parent the parent of the new thread if(proc->isThread == 1){ np->parent = proc->parent; *np->tf = *proc->parent->tf; np->sz = proc->parent->sz; np->pgdir = proc->parent->pgdir; } else{ np->parent = proc; *np->tf = *proc->tf; np->sz = proc->sz; np->pgdir = proc->pgdir; } np->isThread = 1; np->state = RUNNABLE; // Clear %eax so that fork returns 0 in the child. np->tf->eax = 0; pid = np->pid; for(i = 0; i < NOFILE; i++) if(proc->ofile[i]) np->ofile[i] = filedup(proc->ofile[i]); np->cwd = idup(proc->cwd); safestrcpy(np->name, proc->name, sizeof(proc->name)); //safestrcpy(np->name, "ThreadChildren", sizeof("ThreadChildren")); // Push argument strings, prepare rest of stack in ustack. sp = (uint *) ((char *)stack + PGSIZE); sp -= 2; sp[0] = 0xffffffff; // fake return PC sp[1] = (uint) arg; // Commit to the user image.s np->tf->eip = (uint) fcn; // main np->tf->esp = (uint) sp; //cprintf("[proc clone]-pid-%d\n",pid); switchuvm(np); //return pid on success not 0 yo return pid; }
int clone(void(*fcn)(void*), void *arg, void *stack) { // FIX THIS ! int pid; struct proc *newtask; // Copy process state from p. /*if((np->pgdir = copyuvm(proc->pgdir, proc->sz)) == 0){ kfree(np->kstack); np->kstack = 0; np->state = UNUSED; return -1; }*/ // Allocate process. if((newtask = allocproc()) == 0) return -1; newtask->isThread = 1; // labelling as thread newtask->sz = proc->sz; newtask->parent = proc; *newtask->tf = *proc->tf; // Clear %eax so that clone returns 0 in the child. newtask->tf->eax = 0; /*for(i = 0; i < NOFILE; i++) if(proc->ofile[i]) np->ofile[i] = filedup(proc->ofile[i]); np->cwd = idup(proc->cwd);*/ safestrcpy(newtask->name, proc->name, sizeof(proc->name)); pid = newtask->pid; // lock to force the compiler to emit the np->state write last. /* acquire(&ptable.lock); np->state = RUNNABLE; release(&ptable.lock);*/ // temporary array to copy into the bottom of new stack // for the thread (i.e., to the high address in stack // page, since the stack grows downward) uint ustack[2]; uint sp = (uint)stack+PGSIZE; ustack[0] = 0xffffffff; // fake return PC ustack[1] = (uint)arg; sp -= 8; // stack grows down by 2 ints/8 bytes if (copyout(newtask->pgdir, sp, ustack, 8) < 0) { // failed to copy bottom of stack into new task return -1; } newtask->tf->eip = (uint)fcn; newtask->tf->esp = sp; switchuvm(newtask); newtask->state = RUNNABLE; return pid; }
// Per-CPU process scheduler. // Each CPU calls scheduler() after setting itself up. // Scheduler never returns. It loops, doing: // - choose a process to run // - swtch to start running that process // - eventually that process transfers control // via swtch back to the scheduler. void scheduler(void) { struct proc *p; initlock(&tlock, "time"); for(;;){ // Enable interrupts on this processor. sti(); // Loop over process table looking for process to run. acquire(&ptable.lock); for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ if(p->state != RUNNABLE) continue; if(count_high_pri() != 0 && p->priority == 1) continue; // Switch to chosen process. It is the process's job // to release ptable.lock and then reacquire it // before jumping back to us. proc = p; switchuvm(p); p->state = RUNNING; //swtch(&cpu->scheduler, proc->context); //switchkvm(); uint ticks0 = 0, ticks1 = 0; acquire(&tlock);//Acquire the timer lock ticks0 = ticks;//Start timer release(&tlock); swtch(&cpu->scheduler, proc->context); acquire(&tlock);//Acquire the timer lock ticks1 = ticks;//Stop timer and add the ticks to htick or ltick depending upon the priority of the process. release(&tlock); if (p->priority == 1) { p->ltick = p->ltick + (ticks1 - ticks0); } else { p->htick = p->htick + (ticks1 - ticks0); } switchkvm(); // Process is done running for now. // It should have changed its p->state before coming back. proc = 0; } release(&ptable.lock); } }
//PAGEBREAK: 42 // Per-CPU process scheduler. // Each CPU calls scheduler() after setting itself up. // Scheduler never returns. It loops, doing: // - choose a process to run // - swtch to start running that process // - eventually that process transfers control // via swtch back to the scheduler. void scheduler(void) { struct proc *p; int makeShiftTimer = 0; for(;;){ // Enable interrupts on this processor. sti(); makeShiftTimer++; if (makeShiftTimer >= 10000){ for (p = ptable.proc; p < &ptable.proc[NPROC]; p++){ if (p->pri != 1){ continue; } p->pri = 0; //cprintf("Bumping up: %s", p->name); } makeShiftTimer = 0; } int zeroCount = 0; for (p = ptable.proc; p < &ptable.proc[NPROC]; p++){ zeroCount++; } // cprintf("Number of process on queue 0: %d\n", zeroCount); //don't uncomment this if you want to be able to use the terminal. At all. // Loop over process table looking for process to run. acquire(&ptable.lock); for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ if((p->state != RUNNABLE) || (zeroCount != 0 && p->pri == 1)) //im pretty sure the case for there being nothing on the 0 queue and stuff on the 1 queue is implicit here //we'll wait and see I guess continue; // Switch to chosen process. It is the process's job // to release ptable.lock and then reacquire it // before jumping back to us. proc = p; switchuvm(p); p->state = RUNNING; swtch(&cpu->scheduler, proc->context); switchkvm(); // Process is done running for now. // It should have changed its p->state before coming back. proc = 0; } release(&ptable.lock); } }
void handleLeftClick() { WindowQueue *pwindowQueue; Widget *pwidget; pwindowQueue = getClickedWindowQueue(); if (pwindowQueue) { if (pwindowQueue != lastWindow && pwindowQueue == &windowLine[0]) { if (proc == 0) switchkvm(); else switchuvm(proc); return; } if (pwindowQueue != lastWindow && pwindowQueue != &windowLine[0]) { focusDismiss(); reorderQueue(pwindowQueue); switchuvm(pwindowQueue->proc); } pwidget = getClickedWidget(pwindowQueue->window); if (pwidget) { switch (pwidget->type) { case button: focusDismiss(); switchuvm(pwindowQueue->proc); pwidget->context.button->onLeftClickHandler.triggered = 1; break; case imageView: focusDismiss(); switchuvm(pwindowQueue->proc); pwidget->context.imageView->onLeftClickHandler.triggered = 1; break; case iconView: focusIconView(pwidget->context.iconView); break; default: focusDismiss(); switchuvm(pwindowQueue->proc); break; } } else { focusDismiss(); switchuvm(pwindowQueue->proc); } } if (proc == 0) switchkvm(); else switchuvm(proc); }
//PAGEBREAK: 42 // Per-CPU process scheduler. // Each CPU calls scheduler() after setting itself up. // Scheduler never returns. It loops, doing: // - choose a process to run // - swtch to start running that process // - eventually that process transfers control // via swtch back to the scheduler. void scheduler(void) { struct proc *p; int i; #if 0 for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ if(p->state != UNUSED) cprintf("proc %d has priority %d\n", p->pid, p->priority); } #endif for(;;){ // Enable interrupts on this processor. sti(); acquire(&ptable.lock); // Loop through priority queues looking for runnable processe for(i = 0; i < 32; i++) { if(priority_q[i] != NULL) { p = priority_q[i]; #if 0 } } // Loop over process table looking for process to run. for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ #endif if(p->state != RUNNABLE) panic("Not runnable in ready queue"); // Switch to chosen process. It is the process's job // to release ptable.lock and then reacquire it // before jumping back to us. proc = p; switchuvm(p); p->state = RUNNING; //**** remove //cprintf("remove in scheduler\n"); removefromq(p); //**** swtch(&cpu->scheduler, proc->context); switchkvm(); // Process is done running for now. // It should have changed its p->state before coming back. proc = 0; } } release(&ptable.lock); }
void SwitchToProccess(struct proc* process) { proc = process; switchuvm(process); process->state = RUNNING; swtch(&cpu->scheduler, proc->context); switchkvm(); // Process is done running for now. // It should have changed its p->state before coming back. proc = 0; }
int clone(void(*fcn)(void*), void *arg, void *stack) { int i, pid; //cprintf("proc.c void *arg print: %d\n", &arg); struct proc *newtask; // Allocate process. if ((newtask = allocproc()) == 0) return -1; //newtask->kstack = stack; newtask->isThread = 1; // labelling as thread newtask->sz = proc->sz; if (proc->isThread) { newtask->parent = proc->parent; } else { newtask->parent = proc; } *newtask->tf = *proc->tf; newtask->pgdir = proc->pgdir; for(i = 0; i < NOFILE; i++) if(proc->ofile[i]) newtask->ofile[i] = filedup(proc->ofile[i]); newtask->cwd = idup(proc->cwd); safestrcpy(newtask->name, proc->name, sizeof(proc->name)); // Clear %eax so that clone returns 0 in the child. newtask->tf->eax = 0; pid = newtask->pid; // temporary array to copy into the bottom of new stack // for the thread (i.e., to the high address in stack // page, since the stack grows downward) uint ustack[2]; uint sp = (uint)stack+PGSIZE; ustack[0] = 0xffffffff; // fake return PC ustack[1] = (uint)arg; sp -= 8; // stack grows down by 2 ints/8 bytes if (copyout(newtask->pgdir, sp, ustack, 8) < 0) { // failed to copy bottom of stack into new task cprintf("I'm crashing..."); return -1; } newtask->tf->eip = (uint)fcn; newtask->tf->esp = sp; switchuvm(newtask); newtask->state = RUNNABLE; return pid; }
int clone(void (*fcn)(void*), void *arg, void *stack) { int i, pid; struct proc *np; if ((int)stack % PGSIZE != 0) { return -1; } if ((np = allocproc()) == 0) { return -1; } np->pgdir = proc->pgdir; np->sz = proc->sz; if (proc->is_thread == 1) { np->parent = proc->parent; } else { np->parent = proc; } *np->tf = *proc->tf; np->is_thread = 1; np->tf->eax = 0; for(i = 0; i < NOFILE; i++) { if(proc->ofile[i]) { np->ofile[i] = filedup(proc->ofile[i]); } } np->cwd = idup(proc->cwd); safestrcpy(np->name, proc->name, sizeof(proc->name)); pid = np->pid; uint ustack[2]; uint sp = (uint)stack+PGSIZE; ustack[0] = 0xffffffff; ustack[1] = (uint)arg; sp -= 8; if (copyout(np->pgdir, sp, ustack, 8) < 0) { return -1; } np->tf->eip = (uint)fcn; np->tf->esp = sp; switchuvm(np); np->state = RUNNABLE; return pid; }
void scheduler(void) { struct proc *p; ptable.timeToReset = MAX_TIME_TO_RESET; for(;;){ // Enable interrupts on this processor. sti(); // Check for procs in ready list int pri = 0; for (;;) { acquire(&ptable.lock); if(ptable.pPriQ[pri] != 0) { // Switch to chosen process. It is the process's job // to release ptable.lock and then reacquire it // before jumping back to us. p = ptable.pPriQ[pri]; if (p->state != RUNNABLE) panic("scheduled unready process"); proc = p; switchuvm(p); p->state = RUNNING; ptable.pPriQ[pri] = ptable.pPriQ[pri]->next; p->next = 0; ptable.timeToReset--; if (ptable.timeToReset == 0) resetPri(); // Run priority-reset function swtch(&cpu->scheduler, proc->context); switchkvm(); // Process is done running for now. // It should have changed its p->state before coming back. proc = 0; release(&ptable.lock); pri = 0; break; } else { release(&ptable.lock); if (pri == N_PRI-1) pri = 0; else pri++; } } } }
// Grow current process's memory by n bytes. // Return 0 on success, -1 on failure. int growproc(int n) { uint sz = proc->sz; if(n > 0){ if(!(sz = allocuvm(proc->pgdir, sz, sz + n))) return -1; } else if(n < 0){ if(!(sz = deallocuvm(proc->pgdir, sz, sz + n))) return -1; } proc->sz = sz; switchuvm(proc); return 0; }
//PAGEBREAK: 42 // Per-CPU process scheduler. // Each CPU calls scheduler() after setting itself up. // Scheduler never returns. It loops, doing: // - choose a process to run // - swtch to start running that process // - eventually that process transfers control // via swtch back to the scheduler. void scheduler(void) { struct proc *p, *q; unsigned long long min ; for(;;){ // Enable interrupts on this processor. sti(); // Loop over process table looking for process to run. acquire(&ptable.lock); p = 0; min = INFINITO ; for(q = ptable.proc; q < &ptable.proc[NPROC]; q++){ if (q->state == RUNNABLE){ if (min > q->curr_pass){ p = q; min = q->curr_pass; } } } if (p!=0){ /*Testes if (p->pid > 3){ for(q = ptable.proc; q < &ptable.proc[NPROC]; q++){ cprintf("%d %d %d\n", q->pid, q->Ntickts, q->slices); } cprintf("\n\n\n\n"); } End */ p->slices++; proc = p; switchuvm(p); p->state = RUNNING; swtch(&cpu->scheduler, proc->context); switchkvm(); // Process is done running for now. p->curr_pass+=p->pass; // It should have changed its p->state before coming back. proc = 0; } release(&ptable.lock); } }
// Grow current process's memory by n bytes. // Return 0 on success, -1 on failure. int growproc(int n) { uint sz; sz = proc->sz; if(n > 0){ if((sz = allocuvm(proc->pgdir, sz, sz + n)) == 0) // allocate the page return -1; } else if(n < 0){ if((sz = deallocuvm(proc->pgdir, sz, sz + n)) == 0) // deallocate the page return -1; } proc->sz = sz; switchuvm(proc); return 0; }
WindowQueue* getClickedWindowQueue() { WindowQueue *p = lastWindow; int x = mouse_info.x_position; int y = mouse_info.y_position; //get clicked window while (p) { switchuvm(p->proc); if (inWindowRange(p->window, x, y)) { return (p); } p = p->prev; } return 0; }
//PAGEBREAK: 42 // Per-CPU process scheduler. // Each CPU calls scheduler() after setting itself up. // Scheduler never returns. It loops, doing: // - choose a process to run // - swtch to start running that process // - eventually that process transfers control // via swtch back to the scheduler. void scheduler(void) { struct proc *p; for(;;) { // Enable interrupts on this processor. sti(); // Loop over process table looking for process to run. acquire(&ptable.lock); uint min_order = 1<<30; uint idx = -1; for (p = ptable.proc; p < &ptable.proc[NPROC]; p++) if (p->state == RUNNABLE && p->order < min_order) { min_order = p->order; idx = p - ptable.proc; } if (idx == -1) { release(&ptable.lock); continue; } //for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ // if(p->state != RUNNABLE) // continue; // Switch to chosen process. It is the process's job // to release ptable.lock and then reacquire it // before jumping back to us. p = ptable.proc + idx; proc = p; switchuvm(p); p->state = RUNNING; swtch(&cpu->scheduler, proc->context); switchkvm(); // Process is done running for now. // It should have changed its p->state before coming back. proc = 0; //break; //} release(&ptable.lock); } }
//PAGEBREAK: 42 // Per-CPU process scheduler. // Each CPU calls scheduler() after setting itself up. // Scheduler never returns. It loops, doing: // - choose a process to run // - swtch to start running that process // - eventually that process transfers control // via swtch back to the scheduler. void scheduler(void) { struct proc *p; for(;;){ // Enable interrupts on this processor. sti(); // Loop over process table looking for process to run. acquire(&ptable.lock); /* for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ if(p->state != RUNNABLE) continue; */ int i; for(i = 0; i < PRIORITIES; i ++) { p = ready[i]; if(p == 0) continue; // Switch to chosen process. It is the process's job // to release ptable.lock and then reacquire it // before jumping back to us. proc = p; switchuvm(p); p->state = RUNNING; remove_from_ready(p); swtch(&cpu->scheduler, proc->context); switchkvm(); // Process is done running for now. // It should have changed its p->state before coming back. proc = p = 0; /* if(current_priority == 31) current_priority = 0; else current_priority = i + 1; */ } release(&ptable.lock); } }
// Grow current process's memory by n bytes. // Return 0 on success, -1 on failure. int growproc(int n) { uint sz; // cprintf("Before acquire\n"); acquire(&locksbrk); // cprintf("After acquire\n"); sz = proc->sz; if(n > 0){ if((sz = allocuvm(proc->pgdir, sz, sz + n)) == 0) { release(&locksbrk); return -1; } } else if(n < 0){ if((sz = deallocuvm(proc->pgdir, sz, sz + n)) == 0) { release(&locksbrk); return -1; } } proc->sz = sz; struct proc *p; acquire(&ptable.lock); for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ if(/*p->parent == proc &&*/ p->pgdir == proc->pgdir) p->sz=proc->sz; } release(&ptable.lock); // cprintf("Before release\n"); release(&locksbrk); // cprintf("After release\n"); switchuvm(proc); //release(&locksbrk); return 0; }
void scheduler(void) { struct proc *p; for(;;){ // Enable interrupts on this processor. sti(); // Loop over process table looking for process to run. acquire(&ptable.lock); for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ if(p->state != RUNNABLE) continue; // Switch to chosen process. It is the process's job // to release ptable.lock and then reacquire it // before jumping back to us. if (p->allowed_cpu > -1 && p->allowed_cpu == cpu->id) { //cprintf("\n Processing prod %d, at cpu %d", p->pid, cpu->id); } else if (p->allowed_cpu > -1) { //cprintf("\nSkipping proc %d at cpu %d, proc->allowed_cpu %d", p->pid, cpu->id, p->allowed_cpu); continue; } rerun: proc = p; switchuvm(p); p->state = RUNNING; swtch(&cpu->scheduler, proc->context); switchkvm(); // Process is done running for now. // It should have changed its p->state before coming back. if (cpu->preempt_disable_count > 0) { // Go back and reschedule the same process goto rerun; } proc = 0; } release(&ptable.lock); } }
void handleRightClick() { WindowQueue *pwindowQueue; Widget *pwidget; pwindowQueue = getClickedWindowQueue(); if (pwindowQueue) { pwidget = getClickedWidget(pwindowQueue->window); if (pwidget) { } } if (proc == 0) switchkvm(); else switchuvm(proc); }