Mercurial > cgi-bin > hgwebdir.cgi > PR > PR_Implementations > PR__Univ > PR__includes > PR__include
view prqueue.h @ 20:f3cb11baf791
Fully working longjmp, get_sched based. Also OS Portability work included.
Related library_proto-runtime commit: 45dc6d5afb2d
| author | Philipe Louchtch |
|---|---|
| date | Fri, 09 May 2014 11:19:53 +0200 |
| parents | c3829f630c2f |
| children |
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 <pthreads/implement.h> //Part of pthreads-win32, needed for type definitions
13 #include <PR__include/osportability.h>
15 #define TRUE 1
16 #define FALSE 0
18 //================== Private Queue stuff ===================
19 /* It is the data that is shared so only need one mutex. */
20 typedef struct _PrivQueueStruc
21 { void **insertPos;
22 void **extractPos;
23 void **startOfData; //data is pointers
24 void **endOfData; //set when alloc data
25 }
26 PrivQueueStruc;
28 typedef void (*DynArrayFnPtr) ( void * ); //fn has to cast void *
30 PrivQueueStruc* makePrivQ ( );
31 bool32 isEmptyPrivQ ( PrivQueueStruc *Q ); //ret TRUE if empty
32 void* peekPrivQ ( PrivQueueStruc *Q ); //ret NULL if empty
33 void* readPrivQ ( PrivQueueStruc *Q ); //ret NULL if empty
34 void writePrivQ( void *in, PrivQueueStruc *Q );
35 //return false when full
36 bool32 writeIfSpacePrivQ( void * in, PrivQueueStruc* Q );
37 int32 numInPrivQ( PrivQueueStruc *Q );
38 void pushPrivQ( void * in, PrivQueueStruc* Q );
39 void freePrivQ( PrivQueueStruc *Q );
42 //====================== Parallel Queue Stuff ====================
44 //========== pThreads based queue ==========
45 /* It is the data that is shared so only need one mutex. */
46 typedef
47 struct _PThdQueueStruc
48 {
49 pthread_mutex_t mutex_t;
50 pthread_cond_t cond_w_t;
51 pthread_cond_t cond_r_t;
52 int32 count;
53 int32 readPos;
54 int32 writePos;
55 void* data[1024]; //an array of pointers
56 int w_empty;
57 int w_full;
58 }
59 PThdQueueStruc;
61 PThdQueueStruc* makePThdQ();
62 void* readPThdQ( PThdQueueStruc *Q );
63 void writePThdQ( void *in, PThdQueueStruc *Q );
66 //========== CAS based queue ==========
67 typedef
68 struct _CASQueueStruc
69 { volatile int32 insertLock;
70 volatile int32 extractLock;
71 volatile void* *insertPos;
72 volatile void* *extractPos;
73 void* startOfData[1024]; //data is pointers
74 void* *endOfData; //set when make queue
75 }
76 CASQueueStruc;
78 CASQueueStruc* makeCASQ();
79 void* readCASQ( CASQueueStruc *Q );
80 void writeCASQ( void *in, CASQueueStruc *Q );
83 //========= non-atomic instr based queue ===========
84 typedef
85 struct _SRSWQueueStruc
86 { void* *insertPos;
87 void* *extractPos;
88 void* startOfData[1024]; //data is pointers
89 void* *endOfData; //set when make queue
90 }
91 SRSWQueueStruc;
93 SRSWQueueStruc* makeSRSWQ();
94 void freeSRSWQ( SRSWQueueStruc* Q );
95 void* readSRSWQ( SRSWQueueStruc *Q );
96 void writeSRSWQ( void *in, SRSWQueueStruc *Q );
99 //========= non-atomic instr S R M W queue ===========
100 typedef
101 struct _SRMWQueueStruc
102 { int32 lastQReadFrom;
103 int32 numInternalQs;
104 int32 internalQsSz;
105 SRSWQueueStruc* *internalQs;
106 }
107 SRMWQueueStruc;
109 SRMWQueueStruc* makeSRMWQ();
110 int addWriterToSRMWQ( SRMWQueueStruc *Q );
111 void* readSRMWQ( SRMWQueueStruc *Q );
112 void writeSRMWQ( void *in, SRMWQueueStruc *Q, int writerID );
115 #endif /* _PRIVATE_QUEUE_H */
