Mercurial > cgi-bin > hgwebdir.cgi > VMS > C_Libraries > Queue_impl
diff BlockingQueue.c @ 20:b5ae7fbb1f01
Created MC_shared brch
| author | Me@portablequad |
|---|---|
| date | Sat, 11 Feb 2012 20:37:52 -0800 |
| parents | 1ed562d601d9 |
| children | 59781a4c9cf1 |
line diff
1.1 --- a/BlockingQueue.c Tue Feb 07 12:51:29 2012 -0800 1.2 +++ b/BlockingQueue.c Sat Feb 11 20:37:52 2012 -0800 1.3 @@ -18,89 +18,6 @@ 1.4 1.5 #define SPINLOCK_TRIES 100000 1.6 1.7 -//=========================================================================== 1.8 -//Normal pthread Q 1.9 - 1.10 -PThdQueueStruc* makePThdQ() 1.11 - { 1.12 - PThdQueueStruc* retQ; 1.13 - int retCode; 1.14 - retQ = (PThdQueueStruc *) malloc( sizeof( PThdQueueStruc ) ); 1.15 - 1.16 - 1.17 - retCode = 1.18 - pthread_mutex_init( &retQ->mutex_t, NULL); 1.19 - if(retCode){perror("Error in creating mutex:"); exit(1);} 1.20 - 1.21 - retCode = pthread_cond_init ( &retQ->cond_w_t, NULL); 1.22 - if(retCode){perror("Error in creating cond_var:"); exit(1);} 1.23 - 1.24 - retCode = pthread_cond_init ( &retQ->cond_r_t, NULL); 1.25 - if(retCode){perror("Error in creating cond_var:"); exit(1);} 1.26 - 1.27 - retQ->count = 0; 1.28 - retQ->readPos = 0; 1.29 - retQ->writePos = 0; 1.30 - retQ->w_empty = 0; 1.31 - retQ->w_full = 0; 1.32 - 1.33 - return retQ; 1.34 - } 1.35 - 1.36 -void * readPThdQ( PThdQueueStruc *Q ) 1.37 - { void *ret; 1.38 - int retCode, wt; 1.39 - pthread_mutex_lock( &Q->mutex_t ); 1.40 - { 1.41 - while( Q -> count == 0 ) 1.42 - { Q -> w_empty = 1; 1.43 - retCode = 1.44 - pthread_cond_wait( &Q->cond_r_t, &Q->mutex_t ); 1.45 - if( retCode ){ perror("Thread wait error: "); exit(1); } 1.46 - } 1.47 - Q -> w_empty = 0; 1.48 - Q -> count -= 1; 1.49 - ret = Q->data[ Q->readPos ]; 1.50 - INC( Q->readPos ); 1.51 - wt = Q -> w_full; 1.52 - Q -> w_full = 0; 1.53 - } 1.54 - pthread_mutex_unlock( &Q->mutex_t ); 1.55 - if (wt) 1.56 - pthread_cond_signal( &Q->cond_w_t ); 1.57 - 1.58 - //printf("Q out: %d\n", ret); 1.59 - return( ret ); 1.60 - } 1.61 - 1.62 -void writePThdQ( void * in, PThdQueueStruc* Q ) 1.63 - { 1.64 - int status, wt; 1.65 - //printf("Q in: %d\n", in); 1.66 - 1.67 - pthread_mutex_lock( &Q->mutex_t ); 1.68 - { 1.69 - while( Q->count >= 1024 ) 1.70 - { 1.71 - Q -> w_full = 1; 1.72 - status = pthread_cond_wait( &Q->cond_w_t, &Q->mutex_t ); 1.73 - if (status != 0) 1.74 - { perror("Thread wait error: "); 1.75 - exit(1); 1.76 - } 1.77 - } 1.78 - 1.79 - Q -> w_full = 0; 1.80 - Q->count += 1; 1.81 - Q->data[ Q->writePos ] = in; 1.82 - INC( Q->writePos ); 1.83 - wt = Q -> w_empty; 1.84 - Q -> w_empty = 0; 1.85 - } 1.86 - 1.87 - pthread_mutex_unlock( &Q->mutex_t ); 1.88 - if( wt ) pthread_cond_signal( &Q->cond_r_t ); 1.89 - } 1.90 1.91 1.92 //=========================================================================== 1.93 @@ -117,7 +34,7 @@ 1.94 CASQueueStruc* makeCASQ() 1.95 { 1.96 CASQueueStruc* retQ; 1.97 - retQ = (CASQueueStruc *) malloc( sizeof( CASQueueStruc ) ); 1.98 + retQ = (CASQueueStruc *) VMS__malloc( sizeof( CASQueueStruc ) ); 1.99 1.100 retQ->insertLock = UNLOCKED; 1.101 retQ->extractLock= UNLOCKED; 1.102 @@ -242,7 +159,7 @@ 1.103 SRSWQueueStruc* makeSRSWQ() 1.104 { 1.105 SRSWQueueStruc* retQ; 1.106 - retQ = (SRSWQueueStruc *) malloc( sizeof( SRSWQueueStruc ) ); 1.107 + retQ = (SRSWQueueStruc *) VMS__malloc( sizeof( SRSWQueueStruc ) ); 1.108 memset( retQ->startOfData, 0, 1024 * sizeof(void *) ); 1.109 1.110 retQ->extractPos = &(retQ->startOfData[0]); //side by side == empty 1.111 @@ -255,7 +172,7 @@ 1.112 void 1.113 freeSRSWQ( SRSWQueueStruc* Q ) 1.114 { 1.115 - free( Q ); 1.116 + VMS__free( Q ); 1.117 } 1.118 1.119 void* readSRSWQ( SRSWQueueStruc* Q ) 1.120 @@ -381,11 +298,11 @@ 1.121 SRMWQueueStruc* makeSRMWQ() 1.122 { SRMWQueueStruc* retQ; 1.123 1.124 - retQ = (SRMWQueueStruc *) malloc( sizeof( SRMWQueueStruc ) ); 1.125 + retQ = (SRMWQueueStruc *) VMS__malloc( sizeof( SRMWQueueStruc ) ); 1.126 1.127 retQ->numInternalQs = 0; 1.128 retQ->internalQsSz = 10; 1.129 - retQ->internalQs = malloc( retQ->internalQsSz * sizeof(SRSWQueueStruc *)); 1.130 + retQ->internalQs = VMS__malloc( retQ->internalQsSz * sizeof(SRSWQueueStruc *)); 1.131 1.132 retQ->lastQReadFrom = 0; 1.133 1.134 @@ -411,11 +328,11 @@ 1.135 oldSz = Q->internalQsSz; 1.136 oldArray = Q->internalQs; 1.137 Q->internalQsSz *= 2; 1.138 - Q->internalQs = malloc( Q->internalQsSz * sizeof(SRSWQueueStruc *)); 1.139 + Q->internalQs = VMS__malloc( Q->internalQsSz * sizeof(SRSWQueueStruc *)); 1.140 for( i = 0; i < oldSz; i++ ) 1.141 { Q->internalQs[i] = oldArray[i]; 1.142 } 1.143 - free( oldArray ); 1.144 + VMS__free( oldArray ); 1.145 } 1.146 Q->internalQs[ Q->numInternalQs - 1 ] = makeSRSWQ(); 1.147 return Q->numInternalQs - 1;
