home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_06_04
/
v6n4050a.txt
< prev
next >
Wrap
Text File
|
1989-09-28
|
960b
|
48 lines
#include <stdio.h>
#include "q2.h"
static qele_type queue[q_MAX];
static int next_in = 0;
static int next_out = 0;
/* fetch an item from the queue */
qele_type q_get()
{
qele_type rval;
/* first test to see if there is an item */
if (next_in == next_out) return EMPTY;
qele_cpy(rval, queue[next_out++]);
next_out &= q_WRAP;
return rval;
}
/* put an item in the queue */
qele_type q_put(nval)
qele_type nval;
{
qele_type rval;
/* first check to see if the queue is full */
if (((next_in + 1) & q_WRAP) == next_out) return FULL;
qele_cpy(queue[next_in++], nval);
next_in &= q_WRAP;
return NORMAL;
}
/* compute entries in queue */
int q_bsy()
{
return ((next_in + q_MAX) - next_out) & q_WRAP ;
}
/* compute free entries in queue */
int q_free()
{
return q_WRAP - (((next_in + q_MAX) - next_out) & q_WRAP);
}