Mercurial > cgi-bin > hgwebdir.cgi > VMS > C_Libraries > Queue_impl
comparison BlockingQueue.c @ 50:93a5782d064b
adding netbeans project directories to repository
| author | Sean Halle <seanhalle@yahoo.com> |
|---|---|
| date | Fri, 14 Feb 2014 07:54:22 -0800 |
| parents | 1ea30ca7093c |
| children |
comparison
equal
deleted
inserted
replaced
| 20:8f75155fdbfa | 21:91e7ed83036f |
|---|---|
| 12 #include <stdlib.h> | 12 #include <stdlib.h> |
| 13 #include <sched.h> | 13 #include <sched.h> |
| 14 #include <string.h> | 14 #include <string.h> |
| 15 | 15 |
| 16 #include "BlockingQueue.h" | 16 #include "BlockingQueue.h" |
| 17 #include "PR__common_includes/Services_offered_by_PR/Memory_Handling/vmalloc__wrapper_library.h" | 17 #include <PR__include/prqueue.h> |
| 18 #include <PR__include/prmalloc.h> | |
| 18 | 19 |
| 19 #define INC(x) (++x == 1024) ? (x) = 0 : (x) | 20 #define INC(x) (++x == 1024) ? (x) = 0 : (x) |
| 20 | 21 |
| 21 #define SPINLOCK_TRIES 100000 | 22 #define SPINLOCK_TRIES 100000 |
| 22 | 23 |
| 23 | 24 |
| 25 //========================== pthread based queue ========================= | |
| 26 /*Not currently implemented.. however, copied this code from place where | |
| 27 * did equivalent.. Idea is to just make a private queue, then protect | |
| 28 * access with a lock.. copied code snippet below is how access was | |
| 29 * protected.. just roll this inside a "readBlockingQ()" function.. do | |
| 30 * equivalent inside writeBlockingQ() function.. to make one, just add | |
| 31 * the lock to the queue structure.. | |
| 32 */ | |
| 33 /* | |
| 34 production = NULL; | |
| 35 while( production == NULL ) | |
| 36 { pthread_mutex_lock( &queueAccessLock ); | |
| 37 production = readPrivQ( commQ ); | |
| 38 pthread_mutex_unlock( &queueAccessLock ); | |
| 39 // If empty, yields and tries again. | |
| 40 if( production == NULL) sched_yield(); | |
| 41 } | |
| 42 */ | |
| 24 | 43 |
| 25 //=========================================================================== | 44 //=========================================================================== |
| 26 // multi reader multi writer fast Q via CAS | 45 // multi reader multi writer fast Q via CAS |
| 27 #ifndef _GNU_SOURCE | 46 #ifndef _GNU_SOURCE |
| 28 #define _GNU_SOURCE | 47 #define _GNU_SOURCE |
| 34 */ | 53 */ |
| 35 | 54 |
| 36 CASQueueStruc* makeCASQ() | 55 CASQueueStruc* makeCASQ() |
| 37 { | 56 { |
| 38 CASQueueStruc* retQ; | 57 CASQueueStruc* retQ; |
| 39 retQ = (CASQueueStruc *) PR_WL__malloc( sizeof( CASQueueStruc ) ); | 58 retQ = (CASQueueStruc *) PR__malloc( sizeof( CASQueueStruc ) ); |
| 40 | 59 |
| 41 retQ->insertLock = UNLOCKED; | 60 retQ->insertLock = UNLOCKED; |
| 42 retQ->extractLock= UNLOCKED; | 61 retQ->extractLock= UNLOCKED; |
| 43 | 62 |
| 44 retQ->extractPos = (volatile void**)&(retQ->startOfData[0]); //side by side == empty | 63 retQ->extractPos = (volatile void**)&(retQ->startOfData[0]); //side by side == empty |
| 159 */ | 178 */ |
| 160 | 179 |
| 161 SRSWQueueStruc* makeSRSWQ() | 180 SRSWQueueStruc* makeSRSWQ() |
| 162 { | 181 { |
| 163 SRSWQueueStruc* retQ; | 182 SRSWQueueStruc* retQ; |
| 164 retQ = (SRSWQueueStruc *) PR_WL__malloc( sizeof( SRSWQueueStruc ) ); | 183 retQ = (SRSWQueueStruc *) PR__malloc( sizeof( SRSWQueueStruc ) ); |
| 165 memset( retQ->startOfData, 0, 1024 * sizeof(void *) ); | 184 memset( retQ->startOfData, 0, 1024 * sizeof(void *) ); |
| 166 | 185 |
| 167 retQ->extractPos = &(retQ->startOfData[0]); //side by side == empty | 186 retQ->extractPos = &(retQ->startOfData[0]); //side by side == empty |
| 168 retQ->insertPos = &(retQ->startOfData[1]); // so start pos's have to be | 187 retQ->insertPos = &(retQ->startOfData[1]); // so start pos's have to be |
| 169 retQ->endOfData = &(retQ->startOfData[1023]); | 188 retQ->endOfData = &(retQ->startOfData[1023]); |
| 298 */ | 317 */ |
| 299 | 318 |
| 300 SRMWQueueStruc* makeSRMWQ() | 319 SRMWQueueStruc* makeSRMWQ() |
| 301 { SRMWQueueStruc* retQ; | 320 { SRMWQueueStruc* retQ; |
| 302 | 321 |
| 303 retQ = (SRMWQueueStruc *) PR_WL__malloc( sizeof( SRMWQueueStruc ) ); | 322 retQ = (SRMWQueueStruc *) PR__malloc( sizeof( SRMWQueueStruc ) ); |
| 304 | 323 |
| 305 retQ->numInternalQs = 0; | 324 retQ->numInternalQs = 0; |
| 306 retQ->internalQsSz = 10; | 325 retQ->internalQsSz = 10; |
| 307 retQ->internalQs = PR_WL__malloc( retQ->internalQsSz * sizeof(SRSWQueueStruc *)); | 326 retQ->internalQs = PR__malloc( retQ->internalQsSz * sizeof(SRSWQueueStruc *)); |
| 308 | 327 |
| 309 retQ->lastQReadFrom = 0; | 328 retQ->lastQReadFrom = 0; |
| 310 | 329 |
| 311 return retQ; | 330 return retQ; |
| 312 } | 331 } |
| 328 if( Q->numInternalQs >= Q->internalQsSz ) | 347 if( Q->numInternalQs >= Q->internalQsSz ) |
| 329 { //full, so make bigger | 348 { //full, so make bigger |
| 330 oldSz = Q->internalQsSz; | 349 oldSz = Q->internalQsSz; |
| 331 oldArray = Q->internalQs; | 350 oldArray = Q->internalQs; |
| 332 Q->internalQsSz *= 2; | 351 Q->internalQsSz *= 2; |
| 333 Q->internalQs = PR_WL__malloc( Q->internalQsSz * sizeof(SRSWQueueStruc *)); | 352 Q->internalQs = PR__malloc( Q->internalQsSz * sizeof(SRSWQueueStruc *)); |
| 334 for( i = 0; i < oldSz; i++ ) | 353 for( i = 0; i < oldSz; i++ ) |
| 335 { Q->internalQs[i] = oldArray[i]; | 354 { Q->internalQs[i] = oldArray[i]; |
| 336 } | 355 } |
| 337 PR__free( oldArray ); | 356 PR__free( oldArray ); |
| 338 } | 357 } |
