mirror of https://github.com/zrafa/xinu-avr.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.2 KiB
52 lines
1.2 KiB
/* queue.c - enqueue, dequeue */ |
|
|
|
#include <xinu.h> |
|
|
|
struct qentry queuetab[NQENT]; /* Table of process queues */ |
|
|
|
/*------------------------------------------------------------------------ |
|
* enqueue - Insert a process at the tail of a queue |
|
*------------------------------------------------------------------------ |
|
*/ |
|
pid32 enqueue( |
|
pid32 pid, /* ID of process to insert */ |
|
qid16 q /* ID of queue to use */ |
|
) |
|
{ |
|
qid16 tail, prev; /* Tail & previous node indexes */ |
|
|
|
if (isbadqid(q) || isbadpid(pid)) { |
|
return SYSERR; |
|
} |
|
|
|
tail = queuetail(q); |
|
prev = queuetab[tail].qprev; |
|
|
|
queuetab[pid].qnext = tail; /* Insert just before tail node */ |
|
queuetab[pid].qprev = prev; |
|
queuetab[prev].qnext = pid; |
|
queuetab[tail].qprev = pid; |
|
return pid; |
|
} |
|
|
|
/*------------------------------------------------------------------------ |
|
* dequeue - Remove and return the first process on a list |
|
*------------------------------------------------------------------------ |
|
*/ |
|
pid32 dequeue( |
|
qid16 q /* ID of queue to use */ |
|
) |
|
{ |
|
pid32 pid; /* ID of process removed */ |
|
|
|
if (isbadqid(q)) { |
|
return SYSERR; |
|
} else if (isempty(q)) { |
|
return EMPTY; |
|
} |
|
|
|
pid = getfirst(q); |
|
queuetab[pid].qprev = EMPTY; |
|
queuetab[pid].qnext = EMPTY; |
|
return pid; |
|
}
|
|
|