diff BlockingQueue.h @ 0:85af604dee9b

initial add
author Me
date Sat, 22 May 2010 19:51:09 -0700
parents
children 228ca5487d81
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/BlockingQueue.h	Sat May 22 19:51:09 2010 -0700
     1.3 @@ -0,0 +1,72 @@
     1.4 +/*
     1.5 + *  Copyright 2009 OpenSourceStewardshipFoundation.org
     1.6 + *  Licensed under GNU General Public License version 2
     1.7 + *
     1.8 + * Author: seanhalle@yahoo.com
     1.9 + */
    1.10 +
    1.11 +#ifndef _BLOCKING_QUEUE_H
    1.12 +#define	_BLOCKING_QUEUE_H
    1.13 +
    1.14 +#include <pthread.h>
    1.15 +
    1.16 +#define TRUE     1
    1.17 +#define FALSE    0
    1.18 +
    1.19 +#define LOCKED   1
    1.20 +#define UNLOCKED 0
    1.21 +
    1.22 +
    1.23 +/* It is the data that is shared so only need one mutex. */
    1.24 +typedef
    1.25 +struct
    1.26 + {
    1.27 +   pthread_mutex_t  mutex_t;
    1.28 +   pthread_cond_t   cond_w_t;
    1.29 +   pthread_cond_t   cond_r_t;
    1.30 +   int              count;
    1.31 +   int              readPos;
    1.32 +   int              writePos;
    1.33 +   void*            data[1024];  //an array of pointers
    1.34 +   int w_empty;
    1.35 +   int w_full;
    1.36 + }
    1.37 +QueueStruc;
    1.38 +
    1.39 +
    1.40 +typedef
    1.41 +struct
    1.42 + { int              insertLock;
    1.43 +   int              extractLock;
    1.44 +   void*           *insertPos;
    1.45 +   void*           *extractPos;
    1.46 +   void*            startOfData[1024];  //data is pointers
    1.47 +   void*           *endOfData;          //set when make queue
    1.48 + }
    1.49 +CASQueueStruc;
    1.50 +
    1.51 +
    1.52 +typedef
    1.53 +struct
    1.54 + { void*           *insertPos;
    1.55 +   void*           *extractPos;
    1.56 +   void*            startOfData[1024];  //data is pointers
    1.57 +   void*           *endOfData;          //set when make queue
    1.58 + }
    1.59 +SRSWQueueStruc;
    1.60 +
    1.61 +
    1.62 +QueueStruc*     makeQ();
    1.63 +void* readQ( QueueStruc *Q );
    1.64 +void writeQ( void *in, QueueStruc *Q );
    1.65 +
    1.66 +CASQueueStruc*  makeCASQ();
    1.67 +void* readCASQ( CASQueueStruc *Q );
    1.68 +void writeCASQ( void *in, CASQueueStruc *Q );
    1.69 +
    1.70 +SRSWQueueStruc* makeSRSWQ();
    1.71 +void* readSRSWQ( SRSWQueueStruc *Q );
    1.72 +void writeSRSWQ( void *in, SRSWQueueStruc *Q );
    1.73 +
    1.74 +#endif	/* _BLOCKING_QUEUE_H */
    1.75 +