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 insert(short pid, queue q, short key) 00021 { 00022 short next; /* runs through list */ 00023 short prev; 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 next = queuetab[head].next; 00033 while ( (queuetab[next].key >= key) && (next != tail) ) 00034 { next = queuetab[next].next; } 00035 00036 queuetab[pid].next = next; 00037 queuetab[pid].prev = prev = queuetab[next].prev; 00038 queuetab[pid].key = key; 00039 queuetab[prev].next = pid; 00040 queuetab[next].prev = pid; 00041 return OK; 00042 }