Mercurial > cgi-bin > hgwebdir.cgi > VMS > C_Libraries > Queue_impl
comparison PrivateQueue.c @ 15:1ab93714b9c1
Merge pushPrivQ into VMS_malloc brch
| author | SeanHalle |
|---|---|
| date | Thu, 11 Nov 2010 05:16:13 -0800 |
| parents | 447e97a52426 3134d8a1e8e3 |
| children | 8fd77f9430f0 |
comparison
equal
deleted
inserted
replaced
| 8:6418b733a2b9 | 9:16597d9f918b |
|---|---|
| 155 } | 155 } |
| 156 //Q is full | 156 //Q is full |
| 157 return FALSE; | 157 return FALSE; |
| 158 } | 158 } |
| 159 | 159 |
| 160 /*Treats queue as a stack -- no matter contents, if read done right after | |
| 161 * a push, then the pushed item is what comes out. | |
| 162 * Expands the queue size automatically when it's full. | |
| 163 */ | |
| 164 void | |
| 165 pushPrivQ( void * in, PrivQueueStruc* Q ) | |
| 166 { | |
| 167 void **startOfData = Q->startOfData; | |
| 168 void **endOfData = Q->endOfData; | |
| 169 | |
| 170 void **insertPos = Q->insertPos; | |
| 171 void **extractPos = Q->extractPos; | |
| 172 | |
| 173 tryAgain: | |
| 174 //Full? (insert is just below extract when full) | |
| 175 if( extractPos - insertPos != 1 && | |
| 176 !(insertPos == endOfData && extractPos == startOfData)) | |
| 177 { //insert -- but go backwards, inserting at read position then | |
| 178 // move read pos backwards | |
| 179 *(Q->extractPos) = in; | |
| 180 if( extractPos == startOfData ) //write new pos exactly once, correctly | |
| 181 { Q->extractPos = endOfData; //can't overrun then fix it 'cause | |
| 182 } // other thread might read bad pos | |
| 183 else | |
| 184 { Q->extractPos--; | |
| 185 } | |
| 186 return; | |
| 187 } | |
| 188 //Q is full | |
| 189 enlargePrivQ( Q ); | |
| 190 goto tryAgain; | |
| 191 } | |
| 192 | |
| 160 void | 193 void |
| 161 freePrivQ( PrivQueueStruc *Q ) | 194 freePrivQ( PrivQueueStruc *Q ) |
| 162 { | 195 { |
| 163 VMS__free( Q->startOfData ); | 196 VMS__free( Q->startOfData ); |
| 164 VMS__free( Q ); | 197 VMS__free( Q ); |
