/*
 *  Copyright 2009 OpenSourceStewardshipFoundation.org
 *  Licensed under GNU General Public License version 2
 *
 * Author: seanhalle@yahoo.com
 */

#ifndef _BLOCKING_QUEUE_H
#define	_BLOCKING_QUEUE_H

#include <pthread.h>

#define TRUE     1
#define FALSE    0

#define LOCKED   1
#define UNLOCKED 0


/* It is the data that is shared so only need one mutex. */
typedef
struct
 {
   pthread_mutex_t  mutex_t;
   pthread_cond_t   cond_w_t;
   pthread_cond_t   cond_r_t;
   int              count;
   int              readPos;
   int              writePos;
   void*            data[1024];  //an array of pointers
   int w_empty;
   int w_full;
 }
QueueStruc;


typedef
struct
 { int              insertLock;
   int              extractLock;
   void*           *insertPos;
   void*           *extractPos;
   void*            startOfData[1024];  //data is pointers
   void*           *endOfData;          //set when make queue
 }
CASQueueStruc;


typedef
struct
 { void*           *insertPos;
   void*           *extractPos;
   void*            startOfData[1024];  //data is pointers
   void*           *endOfData;          //set when make queue
 }
SRSWQueueStruc;


QueueStruc*     makeQ();
void* readQ( QueueStruc *Q );
void writeQ( void *in, QueueStruc *Q );

CASQueueStruc*  makeCASQ();
void* readCASQ( CASQueueStruc *Q );
void writeCASQ( void *in, CASQueueStruc *Q );

SRSWQueueStruc* makeSRSWQ();
void* readSRSWQ( SRSWQueueStruc *Q );
void writeSRSWQ( void *in, SRSWQueueStruc *Q );

#endif	/* _BLOCKING_QUEUE_H */

