comparison PrivateQueue.c @ 35:3f5e365143fd

New states for sub-repos, almost works, just bug in shutdown to fix still
author Some Random Person <seanhalle@yahoo.com>
date Wed, 14 Mar 2012 23:22:00 -0700
parents 501206566d16
children b9cb01d8ce56
comparison
equal deleted inserted replaced
19:595b35fd1045 21:35ee366125e5
40 } 40 }
41 41
42 42
43 void 43 void
44 enlargePrivQ( PrivQueueStruc *Q ) 44 enlargePrivQ( PrivQueueStruc *Q )
45 { int32 oldSize, newSize; 45 { int32 oldSize, newSize, topPartSize, bottPartSize;
46 int8 *insertPos, *extractPos; 46 int8 *insertPos, *extractPos;
47 int8 *oldStartOfData, *oldEndOfData, *newStartOfData, *newEndOfData; 47 int8 *oldStartOfData, *oldEndOfData, *newStartOfData, *newEndOfData;
48 int8 *insertOffsetBytes, *extractOffsetBytes; 48 int32 insertOffsetBytes, extractOffsetBytes;
49 int8 *copyStartAddr;
49 50
50 oldStartOfData = (int8 *)Q->startOfData; 51 oldStartOfData = (int8 *)Q->startOfData;
51 oldEndOfData = (int8 *)Q->endOfData; 52 oldEndOfData = (int8 *)Q->endOfData;
52 insertPos = (int8 *)Q->insertPos; 53 insertPos = (int8 *)Q->insertPos;
53 extractPos = (int8 *)Q->extractPos; 54 extractPos = (int8 *)Q->extractPos;
54 55
55 //TODO: verify these get number of bytes correct 56 //TODO: verify these get number of bytes correct
56 insertOffsetBytes = insertPos - oldStartOfData; 57 insertOffsetBytes = (int32)(insertPos - oldStartOfData);
57 extractOffsetBytes = extractPos - oldStartOfData); 58 extractOffsetBytes = (int32)(extractPos - oldStartOfData);
58 59
59 oldSize = endOfData - startOfData + 1; //in bytes 60 oldSize = oldEndOfData - oldStartOfData + 1; //in bytes
60 newSize = 2 * oldSize; 61 newSize = 2 * oldSize;
61 62
62 //This malloc is not safe to use in wrapper lib nor app code! 63 //This malloc is not safe to use in wrapper lib nor app code!
63 Q->startOfData = (void **)VMS_int__malloc( newSize ); 64 Q->startOfData = (void **)VMS_int__malloc( newSize );
64 newStartOfData = (int8 *)Q->startOfData; 65 newStartOfData = (int8 *)Q->startOfData;
73 // bottom part of old to bottom part of new, then the new insert 74 // bottom part of old to bottom part of new, then the new insert
74 // and extract positions calculated by offset from top and bottom 75 // and extract positions calculated by offset from top and bottom
75 //UNLESS the one case where old extract was at bottom and insert 76 //UNLESS the one case where old extract was at bottom and insert
76 // was at top. 77 // was at top.
77 //TODO: check that this is correct! 78 //TODO: check that this is correct!
78 if( extractPos == startOfData && insertPos == endOfData ) 79 if( extractPos == oldStartOfData && insertPos == oldEndOfData )
79 { 80 {
80 memcpy( newStartOfData, oldStartOfData, oldSize ); //oldSize is bytes 81 memcpy( newStartOfData, oldStartOfData, oldSize ); //oldSize is bytes
81 Q->extractPos = Q->startOfData; //start of valid data 82 Q->extractPos = Q->startOfData; //start of valid data
82 Q->insertPos = Q->startOfData + oldSize - 1; //end of valid data 83 Q->insertPos = Q->startOfData + oldSize - 1; //end of valid data
83 } 84 }
84 else //have to copy two parts separately, then calc positions 85 else //have to copy two parts separately, then calc positions
85 { //TODO: check end-addr, sizes, and new positions carefully 86 { //TODO: check end-addr, sizes, and new positions carefully
86 87
87 //copy top part, starting at extract up until end of data, 88 //copy top part, starting at extract up until end of data,
88 // into top of new array 89 // into top of new array
89 topPartSize = oldEndOfData - extractPos + 1; //+1 includes extractPos 90 topPartSize = oldEndOfData - extractPos + 1; //+1 includes extractPos
90 copyStartAddr = newEndOfData - topPartSize + 1;//+1 cancels other 91 copyStartAddr = newEndOfData - topPartSize + 1;//+1 cancels other
91 memcpy( copyStartAddr, Q->extractPos, topPartSize ); 92 memcpy( copyStartAddr, Q->extractPos, topPartSize );
92 Q->extractPos = (void **)copyStartAddr; //extract just-copied data 93 Q->extractPos = (void **)copyStartAddr; //extract just-copied data
93 94
94 //copy bottom part, from old start up to old insert, 95 //copy bottom part, from old start up to old insert,
95 // into bottom of new array 96 // into bottom of new array
96 bottPartSize = oldSize - topPartSize - 1; //-1 for empty insertPos 97 bottPartSize = oldSize - topPartSize - 1; //-1 for empty insertPos
97 memcpy( newStartOfData, oldStartOfData, bottPartSize ); 98 memcpy( newStartOfData, oldStartOfData, bottPartSize );
98 Q->insertPos = (void **)(newStartOfData + bottPartSize); 99 Q->insertPos = (void **)(newStartOfData + bottPartSize);
99 } 100 }
100 //This free is not safe to use in wrapper lib nor app code! 101 //This free is not safe to use in wrapper lib nor app code!
161 162
162 163
163 /*Returns false when the queue was full. 164 /*Returns false when the queue was full.
164 * have option of calling make_larger_PrivQ to make more room, then try again 165 * have option of calling make_larger_PrivQ to make more room, then try again
165 */ 166 */
166 int writeIfSpacePrivQ( void * in, PrivQueueStruc* Q ) 167 bool32
168 writeIfSpacePrivQ( void * in, PrivQueueStruc* Q )
167 { 169 {
168 void **startOfData = Q->startOfData; 170 void **startOfData = Q->startOfData;
169 void **endOfData = Q->endOfData; 171 void **endOfData = Q->endOfData;
170 172
171 void **insertPos = Q->insertPos; 173 void **insertPos = Q->insertPos;