view 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
line source
1 /*
2 * File: BlockingQueue.h
3 * Author: SeanHalle@yahoo.com
4 *
5 * Created on November 11, 2009, 12:51 PM
6 */
8 #ifndef _BLOCKINGQUEUE_H
9 #define _BLOCKINGQUEUE_H
11 #include "pthread.h"
14 #define TRUE 1
15 #define FALSE 0
17 #define LOCKED 1
18 #define UNLOCKED 0
21 //========== pThreads based queue ==========
22 /* It is the data that is shared so only need one mutex. */
23 typedef
24 struct
25 { pthread_mutex_t mutex_t;
26 pthread_cond_t cond_w_t;
27 pthread_cond_t cond_r_t;
28 int count;
29 int readPos;
30 int writePos;
31 void* data[1024]; //an array of pointers
32 int w_empty;
33 int w_full;
34 }
35 PThdQueueStruc;
37 PThdQueueStruc* makePThdQ();
38 void* readPThdQ( PThdQueueStruc *Q );
39 void writePThdQ( void *in, PThdQueueStruc *Q );
42 //========== CAS based queue ==========
43 typedef
44 struct
45 { volatile int insertLock;
46 volatile int extractLock;
47 volatile void* *insertPos;
48 volatile void* *extractPos;
49 void* startOfData[1024]; //data is pointers
50 void* *endOfData; //set when make queue
51 }
52 CASQueueStruc;
54 CASQueueStruc* makeCASQ();
55 void* readCASQ( CASQueueStruc *Q );
56 void writeCASQ( void *in, CASQueueStruc *Q );
59 //========= non-atomic instr based queue ===========
60 typedef
61 struct
62 { void* *insertPos;
63 void* *extractPos;
64 void* startOfData[1024]; //data is pointers
65 void* *endOfData; //set when make queue
66 }
67 SRSWQueueStruc;
69 SRSWQueueStruc* makeSRSWQ();
70 void* readSRSWQ( SRSWQueueStruc *Q );
71 void writeSRSWQ( void *in, SRSWQueueStruc *Q );
74 //========= non-atomic instr S R M W queue ===========
75 typedef
76 struct
77 { int lastQReadFrom;
78 int numInternalQs;
79 int internalQsSz;
80 SRSWQueueStruc* *internalQs;
81 }
82 SRMWQueueStruc;
84 SRMWQueueStruc* makeSRMWQ();
85 int addWriterToSRMWQ( SRMWQueueStruc *Q );
86 void* readSRMWQ( SRMWQueueStruc *Q );
87 void writeSRMWQ( void *in, SRMWQueueStruc *Q, int writerID );
90 #endif /* _BLOCKINGQUEUE_H */