From: Jorrit Herder Date: Fri, 20 May 2005 09:37:43 +0000 (+0000) Subject: New system call added to PM: getprocnr(int *proc_nr) (like getpid); X-Git-Tag: v3.1.0~829 X-Git-Url: http://zhaoyanbai.com/repos/%22/xml/v3/status/static/gitweb.js?a=commitdiff_plain;h=d0a5a5d0070e7d983c68c79194a8af276ac66b45;p=minix.git New system call added to PM: getprocnr(int *proc_nr) (like getpid); Minor update to scheduling code (unready(). --- diff --git a/kernel/proc.c b/kernel/proc.c index 54d977864..8c92ee87f 100755 --- a/kernel/proc.c +++ b/kernel/proc.c @@ -575,7 +575,7 @@ register struct proc *rp; /* this process is now runnable */ } /* Run 'rp' next if it has a higher priority than 'proc_ptr'. This actually - * should be done via pick_proc(), but mini_send() and mini_rec() rely + * should be done via pick_proc(), but the message passing functions rely * on this side-effect. */ if (rp->p_priority < proc_ptr->p_priority) proc_ptr = rp; @@ -590,8 +590,8 @@ register struct proc *rp; /* this process is no longer runnable */ /* A process has blocked. See ready for a description of the queues. */ register struct proc *xp; - register struct proc **qtail; /* queue's rdy_tail */ - int q = rp->p_priority; /* queue to use */ + register struct proc **qtail; /* queue's rdy_tail */ + int q = rp->p_priority; /* queue to use */ /* Side-effect for tasks: check if the task's stack still is ok? */ if (istaskp(rp)) { @@ -600,24 +600,34 @@ register struct proc *rp; /* this process is no longer runnable */ } /* Now make sure that the process is not in its ready queue. Remove the - * process if it is found. The easy part is to check the front of the queue. + * process if it is found. A process can be made unready even if it is not + * running by being sent a signal that kills it. */ - if ( (xp = rdy_head[q]) == NIL_PROC) return; - if (xp == rp) { - rdy_head[q] = xp->p_nextready; /* remove head of queue */ - if (rp == proc_ptr) /* current process removed */ - pick_proc(); /* pick new process to run */ - return; + if ( (xp = rdy_head[q]) != NIL_PROC) { /* ready queue is empty */ + if (xp == rp) { /* check head of queue */ + rdy_head[q] = xp->p_nextready; /* new head of queue */ + if (rp == proc_ptr) /* current process removed */ + pick_proc(); /* pick new process to run */ + } + else { /* check body of queue */ + while (xp->p_nextready != rp) /* stop if process is next */ + if ( (xp = xp->p_nextready) == NIL_PROC) + return; + xp->p_nextready = xp->p_nextready->p_nextready; + if (rdy_tail[q] == rp) /* possibly update tail */ + rdy_tail[q] = rp; + } } - /* No match yet. Search body of queue. A process can be made unready even - * if it is not running by being sent a signal that kills it. - */ - while (xp->p_nextready != rp) - if ( (xp = xp->p_nextready) == NIL_PROC) return; + +#if DEAD_CODE + while (xp->p_nextready != rp) /* find rp */ + if ( (xp = xp->p_nextready) == NIL_PROC) + return; xp->p_nextready = xp->p_nextready->p_nextready; qtail = &rdy_tail[q]; if (*qtail == rp) *qtail = xp; +#endif } /*===========================================================================* diff --git a/lib/other/_getprocnr.c b/lib/other/_getprocnr.c new file mode 100644 index 000000000..688a7caba --- /dev/null +++ b/lib/other/_getprocnr.c @@ -0,0 +1,15 @@ +#include +#define getprocnr _getprocnr +#include + + +PUBLIC int getprocnr(proc_nr) +int *proc_nr; /* return process number here */ +{ + message m; + + if (_syscall(MM, GETPROCNR, &m) < 0) return(-1); + *proc_nr = m.m1_i1; + return(0); +} + diff --git a/lib/syscall/getprocnr.s b/lib/syscall/getprocnr.s new file mode 100644 index 000000000..a36c560e3 --- /dev/null +++ b/lib/syscall/getprocnr.s @@ -0,0 +1,7 @@ +.sect .text +.extern __getprocnr +.define _getprocnr +.align 2 + +_getprocnr: + jmp __getprocnr