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.
36 lines
950 B
36 lines
950 B
/* insert.c - insert */ |
|
|
|
#include <xinu.h> |
|
|
|
/*------------------------------------------------------------------------ |
|
* insert - Insert a process into a queue in descending key order |
|
*------------------------------------------------------------------------ |
|
*/ |
|
status insert( |
|
pid32 pid, /* ID of process to insert */ |
|
qid16 q, /* ID of queue to use */ |
|
char key /* Key for the inserted process */ |
|
) |
|
{ |
|
qid16 curr; /* Runs through items in a queue*/ |
|
qid16 prev; /* Holds previous node index */ |
|
|
|
if (isbadqid(q) || isbadpid(pid)) { |
|
return SYSERR; |
|
} |
|
|
|
curr = firstid(q); |
|
while (queuetab[curr].qkey >= key) { |
|
curr = queuetab[curr].qnext; |
|
} |
|
|
|
/* Insert process between curr node and previous node */ |
|
|
|
prev = queuetab[curr].qprev; /* Get index of previous node */ |
|
queuetab[pid].qnext = curr; |
|
queuetab[pid].qprev = prev; |
|
queuetab[pid].qkey = key; |
|
queuetab[prev].qnext = pid; |
|
queuetab[curr].qprev = pid; |
|
return OK; |
|
}
|
|
|