Mercurial > cgi-bin > hgwebdir.cgi > VMS > C_Libraries > Queue_impl
annotate BlockingQueue.h @ 14:447e97a52426
added zeroing out private queue when created
| author | Me |
|---|---|
| date | Thu, 04 Nov 2010 17:56:08 -0700 |
| parents | 08f0b4da7610 |
| children |
| rev | line source |
|---|---|
| Me@5 | 1 /* |
| Me@5 | 2 * File: BlockingQueue.h |
| Me@5 | 3 * Author: SeanHalle@yahoo.com |
| Me@5 | 4 * |
| Me@5 | 5 * Created on November 11, 2009, 12:51 PM |
| Me@5 | 6 */ |
| Me@5 | 7 |
| Me@5 | 8 #ifndef _BLOCKINGQUEUE_H |
| Me@5 | 9 #define _BLOCKINGQUEUE_H |
| Me@5 | 10 |
| Me@5 | 11 #include "pthread.h" |
| Me@5 | 12 |
| Me@5 | 13 |
| Me@5 | 14 #define TRUE 1 |
| Me@5 | 15 #define FALSE 0 |
| Me@5 | 16 |
| Me@5 | 17 #define LOCKED 1 |
| Me@5 | 18 #define UNLOCKED 0 |
| Me@5 | 19 |
| Me@5 | 20 |
| Me@5 | 21 //========== pThreads based queue ========== |
| Me@5 | 22 /* It is the data that is shared so only need one mutex. */ |
| Me@5 | 23 typedef |
| Me@5 | 24 struct |
| Me@5 | 25 { pthread_mutex_t mutex_t; |
| Me@5 | 26 pthread_cond_t cond_w_t; |
| Me@5 | 27 pthread_cond_t cond_r_t; |
| Me@5 | 28 int count; |
| Me@5 | 29 int readPos; |
| Me@5 | 30 int writePos; |
| Me@5 | 31 void* data[1024]; //an array of pointers |
| Me@5 | 32 int w_empty; |
| Me@5 | 33 int w_full; |
| Me@5 | 34 } |
| Me@5 | 35 PThdQueueStruc; |
| Me@5 | 36 |
| Me@5 | 37 PThdQueueStruc* makePThdQ(); |
| Me@5 | 38 void* readPThdQ( PThdQueueStruc *Q ); |
| Me@5 | 39 void writePThdQ( void *in, PThdQueueStruc *Q ); |
| Me@5 | 40 |
| Me@5 | 41 |
| Me@5 | 42 //========== CAS based queue ========== |
| Me@5 | 43 typedef |
| Me@5 | 44 struct |
| Me@9 | 45 { int insertLock; |
| Me@9 | 46 int extractLock; |
| Me@9 | 47 void* *insertPos; |
| Me@9 | 48 void* *extractPos; |
| Me@5 | 49 void* startOfData[1024]; //data is pointers |
| Me@5 | 50 void* *endOfData; //set when make queue |
| Me@5 | 51 } |
| Me@5 | 52 CASQueueStruc; |
| Me@5 | 53 |
| Me@5 | 54 CASQueueStruc* makeCASQ(); |
| Me@5 | 55 void* readCASQ( CASQueueStruc *Q ); |
| Me@5 | 56 void writeCASQ( void *in, CASQueueStruc *Q ); |
| Me@5 | 57 |
| Me@5 | 58 |
| Me@5 | 59 //========= non-atomic instr based queue =========== |
| Me@5 | 60 typedef |
| Me@5 | 61 struct |
| Me@5 | 62 { void* *insertPos; |
| Me@5 | 63 void* *extractPos; |
| Me@5 | 64 void* startOfData[1024]; //data is pointers |
| Me@5 | 65 void* *endOfData; //set when make queue |
| Me@5 | 66 } |
| Me@5 | 67 SRSWQueueStruc; |
| Me@5 | 68 |
| Me@5 | 69 SRSWQueueStruc* makeSRSWQ(); |
| Me@7 | 70 void freeSRSWQ( SRSWQueueStruc* Q ); |
| Me@5 | 71 void* readSRSWQ( SRSWQueueStruc *Q ); |
| Me@7 | 72 void writeSRSWQ( void *in, SRSWQueueStruc *Q ); |
| Me@5 | 73 |
| Me@5 | 74 |
| Me@5 | 75 //========= non-atomic instr S R M W queue =========== |
| Me@5 | 76 typedef |
| Me@5 | 77 struct |
| Me@5 | 78 { int lastQReadFrom; |
| Me@5 | 79 int numInternalQs; |
| Me@5 | 80 int internalQsSz; |
| Me@5 | 81 SRSWQueueStruc* *internalQs; |
| Me@5 | 82 } |
| Me@5 | 83 SRMWQueueStruc; |
| Me@5 | 84 |
| Me@5 | 85 SRMWQueueStruc* makeSRMWQ(); |
| Me@5 | 86 int addWriterToSRMWQ( SRMWQueueStruc *Q ); |
| Me@5 | 87 void* readSRMWQ( SRMWQueueStruc *Q ); |
| Me@5 | 88 void writeSRMWQ( void *in, SRMWQueueStruc *Q, int writerID ); |
| Me@5 | 89 |
| Me@5 | 90 |
| Me@5 | 91 #endif /* _BLOCKINGQUEUE_H */ |
| Me@5 | 92 |
