# HG changeset patch # User Me # Date 1277933704 25200 # Node ID 228ca5487d81aaa9760faad57971c6477f01f49d # Parent 8abcca1590b8bff7d99d0ae937b5c800524036b7 Tested and working on full VMS test diff -r 8abcca1590b8 -r 228ca5487d81 BlockingQueue.h --- a/BlockingQueue.h Wed Jun 30 14:34:56 2010 -0700 +++ b/BlockingQueue.h Wed Jun 30 14:35:04 2010 -0700 @@ -1,72 +1,91 @@ -/* - * 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 - -#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 */ - +/* + * File: BlockingQueue.h + * Author: SeanHalle@yahoo.com + * + * Created on November 11, 2009, 12:51 PM + */ + +#ifndef _BLOCKINGQUEUE_H +#define _BLOCKINGQUEUE_H + +#include "pthread.h" + + +#define TRUE 1 +#define FALSE 0 + +#define LOCKED 1 +#define UNLOCKED 0 + + +//========== pThreads based queue ========== +/* 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; + } +PThdQueueStruc; + +PThdQueueStruc* makePThdQ(); +void* readPThdQ( PThdQueueStruc *Q ); +void writePThdQ( void *in, PThdQueueStruc *Q ); + + +//========== CAS based queue ========== +typedef +struct + { volatile int insertLock; + volatile int extractLock; + volatile void* *insertPos; + volatile void* *extractPos; + void* startOfData[1024]; //data is pointers + void* *endOfData; //set when make queue + } +CASQueueStruc; + +CASQueueStruc* makeCASQ(); +void* readCASQ( CASQueueStruc *Q ); +void writeCASQ( void *in, CASQueueStruc *Q ); + + +//========= non-atomic instr based queue =========== +typedef +struct + { void* *insertPos; + void* *extractPos; + void* startOfData[1024]; //data is pointers + void* *endOfData; //set when make queue + } +SRSWQueueStruc; + +SRSWQueueStruc* makeSRSWQ(); +void* readSRSWQ( SRSWQueueStruc *Q ); +void writeSRSWQ( void *in, SRSWQueueStruc *Q ); + + +//========= non-atomic instr S R M W queue =========== +typedef +struct + { int lastQReadFrom; + int numInternalQs; + int internalQsSz; + SRSWQueueStruc* *internalQs; + } +SRMWQueueStruc; + +SRMWQueueStruc* makeSRMWQ(); +int addWriterToSRMWQ( SRMWQueueStruc *Q ); +void* readSRMWQ( SRMWQueueStruc *Q ); +void writeSRMWQ( void *in, SRMWQueueStruc *Q, int writerID ); + + +#endif /* _BLOCKINGQUEUE_H */ +