view BlockingQueue.h @ 43:d01d48b023ca

Renamed VMS to PR, in new branch
author Sean Halle <seanhalle@yahoo.com>
date Mon, 03 Sep 2012 15:07:45 -0700
parents 555cc068a79a
children 67c7f5a0308b
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 "PR_impl/PR_primitive_data_types.h"
12 #include "PR_impl/Services_Offered_by_PR/Memory_Handling/vmalloc.h"
15 #define TRUE 1
16 #define FALSE 0
18 #define LOCKED 1
19 #define UNLOCKED 0
22 //========== pThreads based queue ==========
23 /* It is the data that is shared so only need one mutex. */
24 typedef
25 struct
26 { pthread_mutex_t mutex_t;
27 pthread_cond_t cond_w_t;
28 pthread_cond_t cond_r_t;
29 int count;
30 int readPos;
31 int writePos;
32 void* data[1024]; //an array of pointers
33 int w_empty;
34 int w_full;
35 }
36 PThdQueueStruc;
38 PThdQueueStruc* makePThdQ();
39 void* readPThdQ( PThdQueueStruc *Q );
40 void writePThdQ( void *in, PThdQueueStruc *Q );
43 //========== CAS based queue ==========
44 typedef
45 struct
46 { volatile int insertLock;
47 volatile int extractLock;
48 volatile void* *insertPos;
49 volatile void* *extractPos;
50 void* startOfData[1024]; //data is pointers
51 void* *endOfData; //set when make queue
52 }
53 CASQueueStruc;
55 CASQueueStruc* makeCASQ();
56 void* readCASQ( CASQueueStruc *Q );
57 void writeCASQ( void *in, CASQueueStruc *Q );
60 //========= non-atomic instr based queue ===========
61 typedef
62 struct
63 { void* *insertPos;
64 void* *extractPos;
65 void* startOfData[1024]; //data is pointers
66 void* *endOfData; //set when make queue
67 }
68 SRSWQueueStruc;
70 SRSWQueueStruc* makeSRSWQ();
71 void freeSRSWQ( SRSWQueueStruc* Q );
72 void* readSRSWQ( SRSWQueueStruc *Q );
73 void writeSRSWQ( void *in, SRSWQueueStruc *Q );
76 //========= non-atomic instr S R M W queue ===========
77 typedef
78 struct
79 { int lastQReadFrom;
80 int numInternalQs;
81 int internalQsSz;
82 SRSWQueueStruc* *internalQs;
83 }
84 SRMWQueueStruc;
86 SRMWQueueStruc* makeSRMWQ();
87 int addWriterToSRMWQ( SRMWQueueStruc *Q );
88 void* readSRMWQ( SRMWQueueStruc *Q );
89 void writeSRMWQ( void *in, SRMWQueueStruc *Q, int writerID );
92 #endif /* _BLOCKINGQUEUE_H */