/*
 */
#ifndef __fifo_h__
#define __fifo_h__

/*
 * This module provides a FIFO queueing service with mutual exclusion.
 * It has both a blocking and a non-blocking dequeue operation.
 */

#include "/usr/include/pthread.h"

typedef struct FIFO 	xk_fifo_t;
typedef struct FIFOEl *	FIFOEl;

struct FIFO {
    FIFOEl	    head;
    FIFOEl	    tail;
    int             nqueued;
    int             nblocked;
    pthread_mutex_t mutex;
    pthread_cond_t  cond;
};

struct FIFOEl {
    FIFOEl	next;
};

extern void	xkFifoInit     (xk_fifo_t* q);
extern int	xkFifoAppend   (xk_fifo_t* q, void *element);
extern void *	xkFifoRemove   (xk_fifo_t* q);
extern void *	xkFifoNBRemove (xk_fifo_t* q);

/* fifoAppend returns TRUE if a thread was waked to handle the newly queued
 * element, and FALSE otherwise.
 */

#endif /* __fifo_h__ */
