diff prqueue.h @ 49:083298a6f7b6

new branch PR_univ_lib -- creates a static library, copied to /usr/lib/PR__lib
author Sean Halle <seanhalle@yahoo.com>
date Sat, 27 Jul 2013 13:10:10 -0700
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/prqueue.h	Sat Jul 27 13:10:10 2013 -0700
     1.3 @@ -0,0 +1,114 @@
     1.4 +/*
     1.5 + *  Copyright 2009 OpenSourceResearchInstitute.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 _PRQUEUE_H
    1.12 +#define	_PRQUEUE_H
    1.13 +
    1.14 +#include <PR__include/PR__primitive_data_types.h>
    1.15 +#include <pthread.h>
    1.16 +
    1.17 +#define TRUE     1
    1.18 +#define FALSE    0
    1.19 +
    1.20 +//==================  Private Queue stuff ===================
    1.21 +/* It is the data that is shared so only need one mutex. */
    1.22 +typedef struct
    1.23 + { void      **insertPos;
    1.24 +   void      **extractPos;
    1.25 +   void      **startOfData;  //data is pointers
    1.26 +   void      **endOfData;    //set when alloc data
    1.27 + }
    1.28 +PrivQueueStruc;
    1.29 +
    1.30 +typedef void  (*DynArrayFnPtr)  ( void * );  //fn has to cast void *
    1.31 +
    1.32 +PrivQueueStruc*  makePrivQ ( );
    1.33 +bool32           isEmptyPrivQ ( PrivQueueStruc *Q ); //ret TRUE if empty
    1.34 +void*            peekPrivQ ( PrivQueueStruc *Q ); //ret NULL if empty
    1.35 +void*            readPrivQ ( PrivQueueStruc *Q ); //ret NULL if empty
    1.36 +void             writePrivQ( void *in, PrivQueueStruc *Q );
    1.37 +                    //return false when full
    1.38 +bool32           writeIfSpacePrivQ( void * in, PrivQueueStruc* Q );
    1.39 +int32            numInPrivQ( PrivQueueStruc *Q );
    1.40 +void             pushPrivQ( void * in, PrivQueueStruc* Q );
    1.41 +void             freePrivQ( PrivQueueStruc *Q );
    1.42 +
    1.43 +
    1.44 +//====================== Parallel Queue Stuff ====================
    1.45 +
    1.46 +//========== pThreads based queue ==========
    1.47 +/* It is the data that is shared so only need one mutex. */
    1.48 +typedef
    1.49 +struct
    1.50 + { pthread_mutex_t  mutex_t;
    1.51 +   pthread_cond_t   cond_w_t;
    1.52 +   pthread_cond_t   cond_r_t;
    1.53 +   int32            count;
    1.54 +   int32            readPos;
    1.55 +   int32            writePos;
    1.56 +   void*            data[1024];  //an array of pointers
    1.57 +   int w_empty;
    1.58 +   int w_full;
    1.59 + }
    1.60 +PThdQueueStruc;
    1.61 +
    1.62 +PThdQueueStruc*     makePThdQ();
    1.63 +void* readPThdQ( PThdQueueStruc *Q );
    1.64 +void writePThdQ( void *in, PThdQueueStruc *Q );
    1.65 +
    1.66 +
    1.67 +//========== CAS based queue ==========
    1.68 +typedef
    1.69 +struct
    1.70 + { volatile int32   insertLock;
    1.71 +   volatile int32   extractLock;
    1.72 +   volatile void*  *insertPos;
    1.73 +   volatile void*  *extractPos;
    1.74 +   void*   startOfData[1024];  //data is pointers
    1.75 +   void*  *endOfData;          //set when make queue
    1.76 + }
    1.77 +CASQueueStruc;
    1.78 +
    1.79 +CASQueueStruc*  makeCASQ();
    1.80 +void* readCASQ( CASQueueStruc *Q );
    1.81 +void writeCASQ( void *in, CASQueueStruc *Q );
    1.82 +
    1.83 +
    1.84 +//========= non-atomic instr based queue ===========
    1.85 +typedef
    1.86 +struct
    1.87 + { void*  *insertPos;
    1.88 +   void*  *extractPos;
    1.89 +   void*   startOfData[1024];  //data is pointers
    1.90 +   void*  *endOfData;          //set when make queue
    1.91 + }
    1.92 +SRSWQueueStruc;
    1.93 +
    1.94 +SRSWQueueStruc* makeSRSWQ();
    1.95 +void  freeSRSWQ( SRSWQueueStruc* Q );
    1.96 +void* readSRSWQ( SRSWQueueStruc *Q );
    1.97 +void  writeSRSWQ( void *in, SRSWQueueStruc *Q );
    1.98 +
    1.99 +
   1.100 +//========= non-atomic instr S R M W queue ===========
   1.101 +typedef
   1.102 +struct
   1.103 + { int32            lastQReadFrom;
   1.104 +   int32            numInternalQs;
   1.105 +   int32            internalQsSz;
   1.106 +   SRSWQueueStruc* *internalQs;
   1.107 + }
   1.108 +SRMWQueueStruc;
   1.109 +
   1.110 +SRMWQueueStruc* makeSRMWQ();
   1.111 +int addWriterToSRMWQ( SRMWQueueStruc *Q );
   1.112 +void* readSRMWQ( SRMWQueueStruc *Q );
   1.113 +void writeSRMWQ( void *in, SRMWQueueStruc *Q, int writerID );
   1.114 +
   1.115 +
   1.116 +#endif	/* _PRIVATE_QUEUE_H */
   1.117 +