Mercurial > cgi-bin > hgwebdir.cgi > PR > PR_Implementations > PR__Univ > PR__includes > PR__include
diff 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 diff
1.1 --- a/prqueue.h Tue Mar 04 12:45:08 2014 -0800 1.2 +++ b/prqueue.h Fri May 09 11:19:53 2014 +0200 1.3 @@ -1,114 +1,116 @@ 1.4 -/* 1.5 - * Copyright 2009 OpenSourceResearchInstitute.org 1.6 - * Licensed under GNU General Public License version 2 1.7 - * 1.8 - * Author: seanhalle@yahoo.com 1.9 - */ 1.10 - 1.11 -#ifndef _PRQUEUE_H 1.12 -#define _PRQUEUE_H 1.13 - 1.14 -#include <PR__include/PR__primitive_data_types.h> 1.15 -#include <pthread.h> 1.16 - 1.17 -#define TRUE 1 1.18 -#define FALSE 0 1.19 - 1.20 -//================== Private Queue stuff =================== 1.21 -/* It is the data that is shared so only need one mutex. */ 1.22 -typedef struct 1.23 - { void **insertPos; 1.24 - void **extractPos; 1.25 - void **startOfData; //data is pointers 1.26 - void **endOfData; //set when alloc data 1.27 - } 1.28 -PrivQueueStruc; 1.29 - 1.30 -typedef void (*DynArrayFnPtr) ( void * ); //fn has to cast void * 1.31 - 1.32 -PrivQueueStruc* makePrivQ ( ); 1.33 -bool32 isEmptyPrivQ ( PrivQueueStruc *Q ); //ret TRUE if empty 1.34 -void* peekPrivQ ( PrivQueueStruc *Q ); //ret NULL if empty 1.35 -void* readPrivQ ( PrivQueueStruc *Q ); //ret NULL if empty 1.36 -void writePrivQ( void *in, PrivQueueStruc *Q ); 1.37 - //return false when full 1.38 -bool32 writeIfSpacePrivQ( void * in, PrivQueueStruc* Q ); 1.39 -int32 numInPrivQ( PrivQueueStruc *Q ); 1.40 -void pushPrivQ( void * in, PrivQueueStruc* Q ); 1.41 -void freePrivQ( PrivQueueStruc *Q ); 1.42 - 1.43 - 1.44 -//====================== Parallel Queue Stuff ==================== 1.45 - 1.46 -//========== pThreads based queue ========== 1.47 -/* It is the data that is shared so only need one mutex. */ 1.48 -typedef 1.49 -struct 1.50 - { pthread_mutex_t mutex_t; 1.51 - pthread_cond_t cond_w_t; 1.52 - pthread_cond_t cond_r_t; 1.53 - int32 count; 1.54 - int32 readPos; 1.55 - int32 writePos; 1.56 - void* data[1024]; //an array of pointers 1.57 - int w_empty; 1.58 - int w_full; 1.59 - } 1.60 -PThdQueueStruc; 1.61 - 1.62 -PThdQueueStruc* makePThdQ(); 1.63 -void* readPThdQ( PThdQueueStruc *Q ); 1.64 -void writePThdQ( void *in, PThdQueueStruc *Q ); 1.65 - 1.66 - 1.67 -//========== CAS based queue ========== 1.68 -typedef 1.69 -struct 1.70 - { volatile int32 insertLock; 1.71 - volatile int32 extractLock; 1.72 - volatile void* *insertPos; 1.73 - volatile void* *extractPos; 1.74 - void* startOfData[1024]; //data is pointers 1.75 - void* *endOfData; //set when make queue 1.76 - } 1.77 -CASQueueStruc; 1.78 - 1.79 -CASQueueStruc* makeCASQ(); 1.80 -void* readCASQ( CASQueueStruc *Q ); 1.81 -void writeCASQ( void *in, CASQueueStruc *Q ); 1.82 - 1.83 - 1.84 -//========= non-atomic instr based queue =========== 1.85 -typedef 1.86 -struct 1.87 - { void* *insertPos; 1.88 - void* *extractPos; 1.89 - void* startOfData[1024]; //data is pointers 1.90 - void* *endOfData; //set when make queue 1.91 - } 1.92 -SRSWQueueStruc; 1.93 - 1.94 -SRSWQueueStruc* makeSRSWQ(); 1.95 -void freeSRSWQ( SRSWQueueStruc* Q ); 1.96 -void* readSRSWQ( SRSWQueueStruc *Q ); 1.97 -void writeSRSWQ( void *in, SRSWQueueStruc *Q ); 1.98 - 1.99 - 1.100 -//========= non-atomic instr S R M W queue =========== 1.101 -typedef 1.102 -struct 1.103 - { int32 lastQReadFrom; 1.104 - int32 numInternalQs; 1.105 - int32 internalQsSz; 1.106 - SRSWQueueStruc* *internalQs; 1.107 - } 1.108 -SRMWQueueStruc; 1.109 - 1.110 -SRMWQueueStruc* makeSRMWQ(); 1.111 -int addWriterToSRMWQ( SRMWQueueStruc *Q ); 1.112 -void* readSRMWQ( SRMWQueueStruc *Q ); 1.113 -void writeSRMWQ( void *in, SRMWQueueStruc *Q, int writerID ); 1.114 - 1.115 - 1.116 -#endif /* _PRIVATE_QUEUE_H */ 1.117 - 1.118 +/* 1.119 + * Copyright 2009 OpenSourceResearchInstitute.org 1.120 + * Licensed under GNU General Public License version 2 1.121 + * 1.122 + * Author: seanhalle@yahoo.com 1.123 + */ 1.124 + 1.125 +#ifndef _PRQUEUE_H 1.126 +#define _PRQUEUE_H 1.127 + 1.128 +#include <PR__include/PR__primitive_data_types.h> 1.129 +//#include <pthreads/implement.h> //Part of pthreads-win32, needed for type definitions 1.130 +#include <PR__include/osportability.h> 1.131 + 1.132 +#define TRUE 1 1.133 +#define FALSE 0 1.134 + 1.135 +//================== Private Queue stuff =================== 1.136 +/* It is the data that is shared so only need one mutex. */ 1.137 +typedef struct _PrivQueueStruc 1.138 + { void **insertPos; 1.139 + void **extractPos; 1.140 + void **startOfData; //data is pointers 1.141 + void **endOfData; //set when alloc data 1.142 + } 1.143 +PrivQueueStruc; 1.144 + 1.145 +typedef void (*DynArrayFnPtr) ( void * ); //fn has to cast void * 1.146 + 1.147 +PrivQueueStruc* makePrivQ ( ); 1.148 +bool32 isEmptyPrivQ ( PrivQueueStruc *Q ); //ret TRUE if empty 1.149 +void* peekPrivQ ( PrivQueueStruc *Q ); //ret NULL if empty 1.150 +void* readPrivQ ( PrivQueueStruc *Q ); //ret NULL if empty 1.151 +void writePrivQ( void *in, PrivQueueStruc *Q ); 1.152 + //return false when full 1.153 +bool32 writeIfSpacePrivQ( void * in, PrivQueueStruc* Q ); 1.154 +int32 numInPrivQ( PrivQueueStruc *Q ); 1.155 +void pushPrivQ( void * in, PrivQueueStruc* Q ); 1.156 +void freePrivQ( PrivQueueStruc *Q ); 1.157 + 1.158 + 1.159 +//====================== Parallel Queue Stuff ==================== 1.160 + 1.161 +//========== pThreads based queue ========== 1.162 +/* It is the data that is shared so only need one mutex. */ 1.163 +typedef 1.164 +struct _PThdQueueStruc 1.165 + { 1.166 + pthread_mutex_t mutex_t; 1.167 + pthread_cond_t cond_w_t; 1.168 + pthread_cond_t cond_r_t; 1.169 + int32 count; 1.170 + int32 readPos; 1.171 + int32 writePos; 1.172 + void* data[1024]; //an array of pointers 1.173 + int w_empty; 1.174 + int w_full; 1.175 + } 1.176 +PThdQueueStruc; 1.177 + 1.178 +PThdQueueStruc* makePThdQ(); 1.179 +void* readPThdQ( PThdQueueStruc *Q ); 1.180 +void writePThdQ( void *in, PThdQueueStruc *Q ); 1.181 + 1.182 + 1.183 +//========== CAS based queue ========== 1.184 +typedef 1.185 +struct _CASQueueStruc 1.186 + { volatile int32 insertLock; 1.187 + volatile int32 extractLock; 1.188 + volatile void* *insertPos; 1.189 + volatile void* *extractPos; 1.190 + void* startOfData[1024]; //data is pointers 1.191 + void* *endOfData; //set when make queue 1.192 + } 1.193 +CASQueueStruc; 1.194 + 1.195 +CASQueueStruc* makeCASQ(); 1.196 +void* readCASQ( CASQueueStruc *Q ); 1.197 +void writeCASQ( void *in, CASQueueStruc *Q ); 1.198 + 1.199 + 1.200 +//========= non-atomic instr based queue =========== 1.201 +typedef 1.202 +struct _SRSWQueueStruc 1.203 + { void* *insertPos; 1.204 + void* *extractPos; 1.205 + void* startOfData[1024]; //data is pointers 1.206 + void* *endOfData; //set when make queue 1.207 + } 1.208 +SRSWQueueStruc; 1.209 + 1.210 +SRSWQueueStruc* makeSRSWQ(); 1.211 +void freeSRSWQ( SRSWQueueStruc* Q ); 1.212 +void* readSRSWQ( SRSWQueueStruc *Q ); 1.213 +void writeSRSWQ( void *in, SRSWQueueStruc *Q ); 1.214 + 1.215 + 1.216 +//========= non-atomic instr S R M W queue =========== 1.217 +typedef 1.218 +struct _SRMWQueueStruc 1.219 + { int32 lastQReadFrom; 1.220 + int32 numInternalQs; 1.221 + int32 internalQsSz; 1.222 + SRSWQueueStruc* *internalQs; 1.223 + } 1.224 +SRMWQueueStruc; 1.225 + 1.226 +SRMWQueueStruc* makeSRMWQ(); 1.227 +int addWriterToSRMWQ( SRMWQueueStruc *Q ); 1.228 +void* readSRMWQ( SRMWQueueStruc *Q ); 1.229 +void writeSRMWQ( void *in, SRMWQueueStruc *Q, int writerID ); 1.230 + 1.231 + 1.232 +#endif /* _PRIVATE_QUEUE_H */ 1.233 +
