00001 00007 /* Embedded XINU, Copyright (C) 2007. All rights reserved. */ 00008 00009 #include <proc.h> 00010 #include <queue.h> 00011 00012 struct qentry queuetab[NQENT]; 00013 static int nextqueue = NPROC; 00021 short enqueue(short pid, queue q) 00022 { 00023 int tail; 00024 00025 if (isbadqueue(q) || isbadpid(pid)) 00026 { return SYSERR; } 00027 00028 tail = queuetail(q); 00029 00030 queuetab[pid].next = tail; 00031 queuetab[pid].prev = queuetab[tail].prev; 00032 queuetab[queuetab[tail].prev].next = pid; 00033 queuetab[tail].prev = pid; 00034 return pid; 00035 } 00036 00037 00043 short remove(short pid) 00044 { 00045 if (isbadpid(pid)) { return SYSERR; } 00046 00047 queuetab[queuetab[pid].prev].next = queuetab[pid].next; 00048 queuetab[queuetab[pid].next].prev = queuetab[pid].prev; 00049 return pid; 00050 } 00051 00057 short dequeue(queue q) 00058 { 00059 int head = queuehead(q); 00060 int pid; /* first process on the list */ 00061 00062 if (isbadqueue(q)) { return SYSERR; } 00063 00064 if ((pid = queuetab[head].next) < NPROC) 00065 { 00066 remove(pid); 00067 queuetab[pid].prev = pid; 00068 queuetab[pid].next = pid; 00069 return pid; 00070 } 00071 else 00072 { return EMPTY; } 00073 } 00074 00079 queue newqueue(void) 00080 { 00081 int head, tail; 00082 00083 head = nextqueue++; 00084 tail = nextqueue++; 00085 queuetab[head].next = tail; 00086 queuetab[head].prev = EMPTY; 00087 queuetab[tail].next = EMPTY; 00088 queuetab[tail].prev = head; 00089 return (queue) ((head << 16) | (tail & 0xFFFF)); 00090 }