00001 00007 /* Embedded XINU, Copyright (C) 2007. All rights reserved. */ 00008 00009 #include <kernel.h> 00010 #include <proc.h> 00011 #include <clock.h> 00012 #include <queue.h> 00013 00014 extern void ctxsw(void *, void *); 00021 syscall resched(void) 00022 { 00023 pcb *oldproc; /* pointer to old process entry */ 00024 pcb *newproc; /* pointer to new process entry */ 00025 00026 oldproc = &proctab[ currpid ]; 00027 00028 oldproc->irqstate = disable(); 00029 00030 /* place current process at end of ready queue */ 00031 if (PRCURR == oldproc->state) 00032 { 00033 oldproc->state = PRREADY; 00034 insert(currpid, readylist, oldproc->prio); 00035 } 00036 00037 /* remove highest priority process in ready queue */ 00038 currpid = dequeue(readylist); 00039 newproc = &proctab[ currpid ]; 00040 newproc->state = PRCURR; /* mark it currently running */ 00041 #ifdef RTCLOCK 00042 preempt = QUANTUM; /* reset preemption counter */ 00043 #endif 00044 00045 ctxsw(&oldproc->stkptr, &newproc->stkptr); 00046 00047 /* The OLD process returns here when resumed. */ 00048 restore(oldproc->irqstate); 00049 return OK; 00050 }