Mercurial > cgi-bin > hgwebdir.cgi > VMS > C_Libraries > Queue_impl
comparison BlockingQueue.c @ 24:677afc259a58
fix branch to compile with new folder structure
| author | Merten Sach <msach@mailbox.tu-berlin.de> |
|---|---|
| date | Mon, 13 Feb 2012 19:32:12 +0100 |
| parents | 1e93e5dbeda1 |
| children |
comparison
equal
deleted
inserted
replaced
| 9:c80b3da18d42 | 13:b66e5ebb3ff7 |
|---|---|
| 11 #include <pthread.h> | 11 #include <pthread.h> |
| 12 #include <stdlib.h> | 12 #include <stdlib.h> |
| 13 #include <sched.h> | 13 #include <sched.h> |
| 14 | 14 |
| 15 #include "BlockingQueue.h" | 15 #include "BlockingQueue.h" |
| 16 #include "../vmalloc.h" | 16 #include "VMS_Implementations/VMS_impl/vmalloc.h" |
| 17 | 17 |
| 18 #define INC(x) (++x == 1024) ? (x) = 0 : (x) | 18 #define INC(x) (++x == 1024) ? (x) = 0 : (x) |
| 19 | 19 |
| 20 #define SPINLOCK_TRIES 100000 | 20 #define SPINLOCK_TRIES 100000 |
| 21 | 21 |
| 24 | 24 |
| 25 PThdQueueStruc* makePThdQ() | 25 PThdQueueStruc* makePThdQ() |
| 26 { | 26 { |
| 27 PThdQueueStruc* retQ; | 27 PThdQueueStruc* retQ; |
| 28 int retCode; | 28 int retCode; |
| 29 retQ = (PThdQueueStruc *) VMS__malloc( sizeof( PThdQueueStruc ) ); | 29 retQ = (PThdQueueStruc *) VMS_int__malloc( sizeof( PThdQueueStruc ) ); |
| 30 | 30 |
| 31 | 31 |
| 32 retCode = | 32 retCode = |
| 33 pthread_mutex_init( &retQ->mutex_t, NULL); | 33 pthread_mutex_init( &retQ->mutex_t, NULL); |
| 34 if(retCode){perror("Error in creating mutex:"); exit(1);} | 34 if(retCode){perror("Error in creating mutex:"); exit(1);} |
| 116 */ | 116 */ |
| 117 | 117 |
| 118 CASQueueStruc* makeCASQ() | 118 CASQueueStruc* makeCASQ() |
| 119 { | 119 { |
| 120 CASQueueStruc* retQ; | 120 CASQueueStruc* retQ; |
| 121 retQ = (CASQueueStruc *) VMS__malloc( sizeof( CASQueueStruc ) ); | 121 retQ = (CASQueueStruc *) VMS_int__malloc( sizeof( CASQueueStruc ) ); |
| 122 | 122 |
| 123 retQ->insertLock = UNLOCKED; | 123 retQ->insertLock = UNLOCKED; |
| 124 retQ->extractLock= UNLOCKED; | 124 retQ->extractLock= UNLOCKED; |
| 125 //TODO: check got pointer syntax right | 125 //TODO: check got pointer syntax right |
| 126 retQ->extractPos = &(retQ->startOfData[0]); //side by side == empty | 126 retQ->extractPos = &(retQ->startOfData[0]); //side by side == empty |
| 241 */ | 241 */ |
| 242 | 242 |
| 243 SRSWQueueStruc* makeSRSWQ() | 243 SRSWQueueStruc* makeSRSWQ() |
| 244 { | 244 { |
| 245 SRSWQueueStruc* retQ; | 245 SRSWQueueStruc* retQ; |
| 246 retQ = (SRSWQueueStruc *) VMS__malloc( sizeof( SRSWQueueStruc ) ); | 246 retQ = (SRSWQueueStruc *) VMS_int__malloc( sizeof( SRSWQueueStruc ) ); |
| 247 | 247 |
| 248 retQ->extractPos = &(retQ->startOfData[0]); //side by side == empty | 248 retQ->extractPos = &(retQ->startOfData[0]); //side by side == empty |
| 249 retQ->insertPos = &(retQ->startOfData[1]); // so start pos's have to be | 249 retQ->insertPos = &(retQ->startOfData[1]); // so start pos's have to be |
| 250 retQ->endOfData = &(retQ->startOfData[1023]); | 250 retQ->endOfData = &(retQ->startOfData[1023]); |
| 251 | 251 |
| 253 } | 253 } |
| 254 | 254 |
| 255 void | 255 void |
| 256 freeSRSWQ( SRSWQueueStruc* Q ) | 256 freeSRSWQ( SRSWQueueStruc* Q ) |
| 257 { | 257 { |
| 258 VMS__free( Q ); | 258 VMS_int__free( Q ); |
| 259 } | 259 } |
| 260 | 260 |
| 261 void* readSRSWQ( SRSWQueueStruc* Q ) | 261 void* readSRSWQ( SRSWQueueStruc* Q ) |
| 262 { void *out = 0; | 262 { void *out = 0; |
| 263 int tries = 0; | 263 int tries = 0; |
| 378 */ | 378 */ |
| 379 | 379 |
| 380 SRMWQueueStruc* makeSRMWQ() | 380 SRMWQueueStruc* makeSRMWQ() |
| 381 { SRMWQueueStruc* retQ; | 381 { SRMWQueueStruc* retQ; |
| 382 | 382 |
| 383 retQ = (SRMWQueueStruc *) VMS__malloc( sizeof( SRMWQueueStruc ) ); | 383 retQ = (SRMWQueueStruc *) VMS_int__malloc( sizeof( SRMWQueueStruc ) ); |
| 384 | 384 |
| 385 retQ->numInternalQs = 0; | 385 retQ->numInternalQs = 0; |
| 386 retQ->internalQsSz = 10; | 386 retQ->internalQsSz = 10; |
| 387 retQ->internalQs = VMS__malloc( retQ->internalQsSz * | 387 retQ->internalQs = VMS_int__malloc( retQ->internalQsSz * |
| 388 sizeof(SRSWQueueStruc *) ); | 388 sizeof(SRSWQueueStruc *) ); |
| 389 | 389 |
| 390 retQ->lastQReadFrom = 0; | 390 retQ->lastQReadFrom = 0; |
| 391 | 391 |
| 392 return retQ; | 392 return retQ; |
| 409 if( Q->numInternalQs >= Q->internalQsSz ) | 409 if( Q->numInternalQs >= Q->internalQsSz ) |
| 410 { //full, so make bigger | 410 { //full, so make bigger |
| 411 oldSz = Q->internalQsSz; | 411 oldSz = Q->internalQsSz; |
| 412 oldArray = Q->internalQs; | 412 oldArray = Q->internalQs; |
| 413 Q->internalQsSz *= 2; | 413 Q->internalQsSz *= 2; |
| 414 Q->internalQs = VMS__malloc( Q->internalQsSz * sizeof(SRSWQueueStruc *)); | 414 Q->internalQs = VMS_int__malloc( Q->internalQsSz * sizeof(SRSWQueueStruc *)); |
| 415 for( i = 0; i < oldSz; i++ ) | 415 for( i = 0; i < oldSz; i++ ) |
| 416 { Q->internalQs[i] = oldArray[i]; | 416 { Q->internalQs[i] = oldArray[i]; |
| 417 } | 417 } |
| 418 VMS__free( oldArray ); | 418 VMS_int__free( oldArray ); |
| 419 } | 419 } |
| 420 Q->internalQs[ Q->numInternalQs - 1 ] = makeSRSWQ(); | 420 Q->internalQs[ Q->numInternalQs - 1 ] = makeSRSWQ(); |
| 421 return Q->numInternalQs - 1; | 421 return Q->numInternalQs - 1; |
| 422 } | 422 } |
| 423 | 423 |
