view prqueue.h @ 3:c3829f630c2f

Merge
author Sean Halle <seanhalle@yahoo.com>
date Sat, 14 Sep 2013 16:57:45 -0700
parents 14241f07f742
children f3cb11baf791
line source
1 /*
2 * Copyright 2009 OpenSourceResearchInstitute.org
3 * Licensed under GNU General Public License version 2
4 *
5 * Author: seanhalle@yahoo.com
6 */
8 #ifndef _PRQUEUE_H
9 #define _PRQUEUE_H
11 #include <PR__include/PR__primitive_data_types.h>
12 #include <pthread.h>
14 #define TRUE 1
15 #define FALSE 0
17 //================== Private Queue stuff ===================
18 /* It is the data that is shared so only need one mutex. */
19 typedef struct
20 { void **insertPos;
21 void **extractPos;
22 void **startOfData; //data is pointers
23 void **endOfData; //set when alloc data
24 }
25 PrivQueueStruc;
27 typedef void (*DynArrayFnPtr) ( void * ); //fn has to cast void *
29 PrivQueueStruc* makePrivQ ( );
30 bool32 isEmptyPrivQ ( PrivQueueStruc *Q ); //ret TRUE if empty
31 void* peekPrivQ ( PrivQueueStruc *Q ); //ret NULL if empty
32 void* readPrivQ ( PrivQueueStruc *Q ); //ret NULL if empty
33 void writePrivQ( void *in, PrivQueueStruc *Q );
34 //return false when full
35 bool32 writeIfSpacePrivQ( void * in, PrivQueueStruc* Q );
36 int32 numInPrivQ( PrivQueueStruc *Q );
37 void pushPrivQ( void * in, PrivQueueStruc* Q );
38 void freePrivQ( PrivQueueStruc *Q );
41 //====================== Parallel Queue Stuff ====================
43 //========== pThreads based queue ==========
44 /* It is the data that is shared so only need one mutex. */
45 typedef
46 struct
47 { pthread_mutex_t mutex_t;
48 pthread_cond_t cond_w_t;
49 pthread_cond_t cond_r_t;
50 int32 count;
51 int32 readPos;
52 int32 writePos;
53 void* data[1024]; //an array of pointers
54 int w_empty;
55 int w_full;
56 }
57 PThdQueueStruc;
59 PThdQueueStruc* makePThdQ();
60 void* readPThdQ( PThdQueueStruc *Q );
61 void writePThdQ( void *in, PThdQueueStruc *Q );
64 //========== CAS based queue ==========
65 typedef
66 struct
67 { volatile int32 insertLock;
68 volatile int32 extractLock;
69 volatile void* *insertPos;
70 volatile void* *extractPos;
71 void* startOfData[1024]; //data is pointers
72 void* *endOfData; //set when make queue
73 }
74 CASQueueStruc;
76 CASQueueStruc* makeCASQ();
77 void* readCASQ( CASQueueStruc *Q );
78 void writeCASQ( void *in, CASQueueStruc *Q );
81 //========= non-atomic instr based queue ===========
82 typedef
83 struct
84 { void* *insertPos;
85 void* *extractPos;
86 void* startOfData[1024]; //data is pointers
87 void* *endOfData; //set when make queue
88 }
89 SRSWQueueStruc;
91 SRSWQueueStruc* makeSRSWQ();
92 void freeSRSWQ( SRSWQueueStruc* Q );
93 void* readSRSWQ( SRSWQueueStruc *Q );
94 void writeSRSWQ( void *in, SRSWQueueStruc *Q );
97 //========= non-atomic instr S R M W queue ===========
98 typedef
99 struct
100 { int32 lastQReadFrom;
101 int32 numInternalQs;
102 int32 internalQsSz;
103 SRSWQueueStruc* *internalQs;
104 }
105 SRMWQueueStruc;
107 SRMWQueueStruc* makeSRMWQ();
108 int addWriterToSRMWQ( SRMWQueueStruc *Q );
109 void* readSRMWQ( SRMWQueueStruc *Q );
110 void writeSRMWQ( void *in, SRMWQueueStruc *Q, int writerID );
113 #endif /* _PRIVATE_QUEUE_H */