Annotation of xinu/sys/resched.c, revision 1.1

1.1     ! root        1: /* resched.c  -  resched */
        !             2: 
        !             3: #include <conf.h>
        !             4: #include <kernel.h>
        !             5: #include <proc.h>
        !             6: #include <q.h>
        !             7: 
        !             8: /*------------------------------------------------------------------------
        !             9:  * resched  --  reschedule processor to highest priority ready process
        !            10:  *
        !            11:  * Notes:      Upon entry, currpid gives current process id.
        !            12:  *             Proctab[currpid].pstate gives correct NEXT state for
        !            13:  *                     current process if other than PRCURR.
        !            14:  *------------------------------------------------------------------------
        !            15:  */
        !            16: int    resched()
        !            17: {
        !            18:        register struct pentry  *optr;  /* pointer to old process entry */
        !            19:        register struct pentry  *nptr;  /* pointer to new process entry */
        !            20: 
        !            21:        /* no switch needed if current process priority higher than next*/
        !            22: 
        !            23:        if ( ( (optr= &proctab[currpid])->pstate == PRCURR) &&
        !            24:           (lastkey(rdytail)<optr->pprio))
        !            25:                return(OK);
        !            26: 
        !            27:        /* force context switch */
        !            28: 
        !            29:        if (optr->pstate == PRCURR) {
        !            30:                optr->pstate = PRREADY;
        !            31:                insert(currpid,rdyhead,optr->pprio);
        !            32:        }
        !            33: 
        !            34:        /* remove highest priority process at end of ready list */
        !            35: 
        !            36:        nptr = &proctab[ (currpid = getlast(rdytail)) ];
        !            37:        nptr->pstate = PRCURR;          /* mark it currently running    */
        !            38: #ifdef STKCHK
        !            39:        if ( *( (int *)nptr->pbase  ) != MAGIC ) {
        !            40:                kprintf("Bad magic pid=%d, value=%x, at %x\n",
        !            41:                        currpid, *( (int *)nptr->pbase ), nptr->pbase);
        !            42:                panic("stack corrupted");
        !            43:        }
        !            44:        if ( ((unsigned)nptr->pregs[SPINDX]) < ((unsigned)nptr->plimit) ) {
        !            45:                kprintf("Bad SP pid=%d (%s), lim=%x will be %x\n",
        !            46:                        currpid, nptr->pname, nptr->plimit,
        !            47:                        nptr->pregs[SPINDX]);
        !            48:                panic("stack overflow");
        !            49:        }
        !            50: #endif
        !            51: #ifdef RTCLOCK
        !            52:        preempt = QUANTUM;              /* reset preemption counter     */
        !            53: #endif
        !            54:        ctxsw(nptr->pregs);
        !            55:        return(OK);
        !            56: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.