Philipe@20: /* Philipe@20: * Copyright 2009 OpenSourceResearchInstitute.org Philipe@20: * Licensed under GNU General Public License version 2 Philipe@20: * Philipe@20: * Author: seanhalle@yahoo.com Philipe@20: */ Philipe@20: Philipe@20: #ifndef _PRQUEUE_H Philipe@20: #define _PRQUEUE_H Philipe@20: Philipe@20: #include Philipe@20: //#include //Part of pthreads-win32, needed for type definitions Philipe@20: #include Philipe@20: Philipe@20: #define TRUE 1 Philipe@20: #define FALSE 0 Philipe@20: Philipe@20: //================== Private Queue stuff =================== Philipe@20: /* It is the data that is shared so only need one mutex. */ Philipe@20: typedef struct _PrivQueueStruc Philipe@20: { void **insertPos; Philipe@20: void **extractPos; Philipe@20: void **startOfData; //data is pointers Philipe@20: void **endOfData; //set when alloc data Philipe@20: } Philipe@20: PrivQueueStruc; Philipe@20: Philipe@20: typedef void (*DynArrayFnPtr) ( void * ); //fn has to cast void * Philipe@20: Philipe@20: PrivQueueStruc* makePrivQ ( ); Philipe@20: bool32 isEmptyPrivQ ( PrivQueueStruc *Q ); //ret TRUE if empty Philipe@20: void* peekPrivQ ( PrivQueueStruc *Q ); //ret NULL if empty Philipe@20: void* readPrivQ ( PrivQueueStruc *Q ); //ret NULL if empty Philipe@20: void writePrivQ( void *in, PrivQueueStruc *Q ); Philipe@20: //return false when full Philipe@20: bool32 writeIfSpacePrivQ( void * in, PrivQueueStruc* Q ); Philipe@20: int32 numInPrivQ( PrivQueueStruc *Q ); Philipe@20: void pushPrivQ( void * in, PrivQueueStruc* Q ); Philipe@20: void freePrivQ( PrivQueueStruc *Q ); Philipe@20: Philipe@20: Philipe@20: //====================== Parallel Queue Stuff ==================== Philipe@20: Philipe@20: //========== pThreads based queue ========== Philipe@20: /* It is the data that is shared so only need one mutex. */ Philipe@20: typedef Philipe@20: struct _PThdQueueStruc Philipe@20: { Philipe@20: pthread_mutex_t mutex_t; Philipe@20: pthread_cond_t cond_w_t; Philipe@20: pthread_cond_t cond_r_t; Philipe@20: int32 count; Philipe@20: int32 readPos; Philipe@20: int32 writePos; Philipe@20: void* data[1024]; //an array of pointers Philipe@20: int w_empty; Philipe@20: int w_full; Philipe@20: } Philipe@20: PThdQueueStruc; Philipe@20: Philipe@20: PThdQueueStruc* makePThdQ(); Philipe@20: void* readPThdQ( PThdQueueStruc *Q ); Philipe@20: void writePThdQ( void *in, PThdQueueStruc *Q ); Philipe@20: Philipe@20: Philipe@20: //========== CAS based queue ========== Philipe@20: typedef Philipe@20: struct _CASQueueStruc Philipe@20: { volatile int32 insertLock; Philipe@20: volatile int32 extractLock; Philipe@20: volatile void* *insertPos; Philipe@20: volatile void* *extractPos; Philipe@20: void* startOfData[1024]; //data is pointers Philipe@20: void* *endOfData; //set when make queue Philipe@20: } Philipe@20: CASQueueStruc; Philipe@20: Philipe@20: CASQueueStruc* makeCASQ(); Philipe@20: void* readCASQ( CASQueueStruc *Q ); Philipe@20: void writeCASQ( void *in, CASQueueStruc *Q ); Philipe@20: Philipe@20: Philipe@20: //========= non-atomic instr based queue =========== Philipe@20: typedef Philipe@20: struct _SRSWQueueStruc Philipe@20: { void* *insertPos; Philipe@20: void* *extractPos; Philipe@20: void* startOfData[1024]; //data is pointers Philipe@20: void* *endOfData; //set when make queue Philipe@20: } Philipe@20: SRSWQueueStruc; Philipe@20: Philipe@20: SRSWQueueStruc* makeSRSWQ(); Philipe@20: void freeSRSWQ( SRSWQueueStruc* Q ); Philipe@20: void* readSRSWQ( SRSWQueueStruc *Q ); Philipe@20: void writeSRSWQ( void *in, SRSWQueueStruc *Q ); Philipe@20: Philipe@20: Philipe@20: //========= non-atomic instr S R M W queue =========== Philipe@20: typedef Philipe@20: struct _SRMWQueueStruc Philipe@20: { int32 lastQReadFrom; Philipe@20: int32 numInternalQs; Philipe@20: int32 internalQsSz; Philipe@20: SRSWQueueStruc* *internalQs; Philipe@20: } Philipe@20: SRMWQueueStruc; Philipe@20: Philipe@20: SRMWQueueStruc* makeSRMWQ(); Philipe@20: int addWriterToSRMWQ( SRMWQueueStruc *Q ); Philipe@20: void* readSRMWQ( SRMWQueueStruc *Q ); Philipe@20: void writeSRMWQ( void *in, SRMWQueueStruc *Q, int writerID ); Philipe@20: Philipe@20: Philipe@20: #endif /* _PRIVATE_QUEUE_H */ Philipe@20: