Mercurial > cgi-bin > hgwebdir.cgi > VMS > C_Libraries > Queue_impl
annotate BlockingQueue.h @ 5:228ca5487d81
Tested and working on full VMS test
| author | Me |
|---|---|
| date | Wed, 30 Jun 2010 14:35:04 -0700 |
| parents | 85af604dee9b |
| children | 08f0b4da7610 |
| 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@5 | 45 { volatile int insertLock; |
| Me@5 | 46 volatile int extractLock; |
| Me@5 | 47 volatile void* *insertPos; |
| Me@5 | 48 volatile 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@5 | 70 void* readSRSWQ( SRSWQueueStruc *Q ); |
| Me@5 | 71 void writeSRSWQ( void *in, SRSWQueueStruc *Q ); |
| Me@5 | 72 |
| Me@5 | 73 |
| Me@5 | 74 //========= non-atomic instr S R M W queue =========== |
| Me@5 | 75 typedef |
| Me@5 | 76 struct |
| Me@5 | 77 { int lastQReadFrom; |
| Me@5 | 78 int numInternalQs; |
| Me@5 | 79 int internalQsSz; |
| Me@5 | 80 SRSWQueueStruc* *internalQs; |
| Me@5 | 81 } |
| Me@5 | 82 SRMWQueueStruc; |
| Me@5 | 83 |
| Me@5 | 84 SRMWQueueStruc* makeSRMWQ(); |
| Me@5 | 85 int addWriterToSRMWQ( SRMWQueueStruc *Q ); |
| Me@5 | 86 void* readSRMWQ( SRMWQueueStruc *Q ); |
| Me@5 | 87 void writeSRMWQ( void *in, SRMWQueueStruc *Q, int writerID ); |
| Me@5 | 88 |
| Me@5 | 89 |
| Me@5 | 90 #endif /* _BLOCKINGQUEUE_H */ |
| Me@5 | 91 |
