ack/mach/proto/top/queue.c

77 lines
1.2 KiB
C
Raw Normal View History

1987-03-09 19:15:41 +00:00
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
1986-11-24 20:58:35 +00:00
#include "top.h"
#include "queue.h"
empty_queue(q)
1987-02-07 00:04:05 +00:00
register queue q;
1986-11-24 20:58:35 +00:00
{
q->head = q->tail = (instr_p) 0;
q->qlen = 0;
}
int empty(q)
queue q;
{
return q->qlen == 0;
}
remove_head(q)
1987-02-07 00:04:05 +00:00
register queue q;
1986-11-24 20:58:35 +00:00
{
if ( (q->head = q->head->fw) == (instr_p) 0) {
q->tail = (instr_p) 0;
} else {
q->head->bw = (instr_p) 0;
}
q->qlen--;
}
add(q,instr)
register queue q;
register instr_p instr;
{
if (q->qlen++ == 0) {
q->head = q->tail = instr;
instr->bw = (instr_p) 0;
} else {
q->tail->fw = instr;
instr->bw = q->tail;
q->tail = instr;
}
instr->fw = (instr_p) 0;
}
insert(q,instr)
1987-02-07 00:04:05 +00:00
register queue q;
register instr_p instr;
1986-11-24 20:58:35 +00:00
{
if (q->qlen++ == 0) {
q->head = q->tail = instr;
instr->fw = (instr_p) 0;
} else {
q->head->bw = instr;
instr->fw = q->head;
q->head = instr;
}
instr->bw = (instr_p) 0;
}
join_queues(q1,q2)
1987-02-07 00:04:05 +00:00
register queue q1,q2;
1986-11-24 20:58:35 +00:00
{
if (q1->qlen > 0) {
q2->qlen += q1->qlen;
q1->tail->fw = q2->head;
if (q2->qlen > 0) {
q2->head->bw = q1->tail;
} else {
q2->tail = q1->tail;
}
q2->head = q1->head;
empty_queue(q1);
}
}