00001 00007 /* Embedded XINU, Copyright (C) 2007. All rights reserved. */ 00008 00009 #include <kernel.h> 00010 #include <proc.h> 00011 #include <queue.h> 00012 00020 short insertd(short pid, queue q, short key) 00021 { 00022 short next; /* runs through list */ 00023 short prev; /* follows next through list */ 00024 short head, tail; 00025 00026 if (isbadqueue(q) || isbadpid(pid)) 00027 { return SYSERR; } 00028 00029 head = queuehead(q); 00030 tail = queuetail(q); 00031 00032 prev = head; 00033 next = queuetab[head].next; 00034 while ( (queuetab[next].key <= key) && (next != tail) ) 00035 { 00036 key -= queuetab[next].key; 00037 prev = next; 00038 next = queuetab[next].next; 00039 } 00040 queuetab[pid].next = next; 00041 queuetab[pid].prev = prev; 00042 queuetab[pid].key = key; 00043 queuetab[prev].next = pid; 00044 queuetab[next].prev = pid; 00045 if (next != tail) 00046 { queuetab[next].key -= key; } 00047 00048 return OK; 00049 }