# HG changeset patch # User Some Random Person # Date 1331792520 25200 # Node ID 3f5e365143fd46dde395bf6ec9bd67395022277c # Parent 501206566d1694f34385e203f03343dc1b3f06dd New states for sub-repos, almost works, just bug in shutdown to fix still diff -r 501206566d16 -r 3f5e365143fd PrivateQueue.c --- a/PrivateQueue.c Wed Mar 14 22:56:28 2012 -0700 +++ b/PrivateQueue.c Wed Mar 14 23:22:00 2012 -0700 @@ -42,10 +42,11 @@ void enlargePrivQ( PrivQueueStruc *Q ) - { int32 oldSize, newSize; + { int32 oldSize, newSize, topPartSize, bottPartSize; int8 *insertPos, *extractPos; int8 *oldStartOfData, *oldEndOfData, *newStartOfData, *newEndOfData; - int8 *insertOffsetBytes, *extractOffsetBytes; + int32 insertOffsetBytes, extractOffsetBytes; + int8 *copyStartAddr; oldStartOfData = (int8 *)Q->startOfData; oldEndOfData = (int8 *)Q->endOfData; @@ -53,10 +54,10 @@ extractPos = (int8 *)Q->extractPos; //TODO: verify these get number of bytes correct - insertOffsetBytes = insertPos - oldStartOfData; - extractOffsetBytes = extractPos - oldStartOfData); + insertOffsetBytes = (int32)(insertPos - oldStartOfData); + extractOffsetBytes = (int32)(extractPos - oldStartOfData); - oldSize = endOfData - startOfData + 1; //in bytes + oldSize = oldEndOfData - oldStartOfData + 1; //in bytes newSize = 2 * oldSize; //This malloc is not safe to use in wrapper lib nor app code! @@ -75,7 +76,7 @@ //UNLESS the one case where old extract was at bottom and insert // was at top. //TODO: check that this is correct! - if( extractPos == startOfData && insertPos == endOfData ) + if( extractPos == oldStartOfData && insertPos == oldEndOfData ) { memcpy( newStartOfData, oldStartOfData, oldSize ); //oldSize is bytes Q->extractPos = Q->startOfData; //start of valid data @@ -83,16 +84,16 @@ } else //have to copy two parts separately, then calc positions { //TODO: check end-addr, sizes, and new positions carefully - + //copy top part, starting at extract up until end of data, - // into top of new array + // into top of new array topPartSize = oldEndOfData - extractPos + 1; //+1 includes extractPos - copyStartAddr = newEndOfData - topPartSize + 1;//+1 cancels other + copyStartAddr = newEndOfData - topPartSize + 1;//+1 cancels other memcpy( copyStartAddr, Q->extractPos, topPartSize ); - Q->extractPos = (void **)copyStartAddr; //extract just-copied data - + Q->extractPos = (void **)copyStartAddr; //extract just-copied data + //copy bottom part, from old start up to old insert, - // into bottom of new array + // into bottom of new array bottPartSize = oldSize - topPartSize - 1; //-1 for empty insertPos memcpy( newStartOfData, oldStartOfData, bottPartSize ); Q->insertPos = (void **)(newStartOfData + bottPartSize); @@ -163,7 +164,8 @@ /*Returns false when the queue was full. * have option of calling make_larger_PrivQ to make more room, then try again */ -int writeIfSpacePrivQ( void * in, PrivQueueStruc* Q ) +bool32 +writeIfSpacePrivQ( void * in, PrivQueueStruc* Q ) { void **startOfData = Q->startOfData; void **endOfData = Q->endOfData;