changeset 35:3f5e365143fd MC_shared

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
files PrivateQueue.c
diffstat 1 files changed, 15 insertions(+), 13 deletions(-) [+]
line diff
     1.1 --- a/PrivateQueue.c	Wed Mar 14 22:56:28 2012 -0700
     1.2 +++ b/PrivateQueue.c	Wed Mar 14 23:22:00 2012 -0700
     1.3 @@ -42,10 +42,11 @@
     1.4  
     1.5  void
     1.6  enlargePrivQ( PrivQueueStruc *Q )
     1.7 - { int32  oldSize, newSize;
     1.8 + { int32  oldSize, newSize, topPartSize, bottPartSize;
     1.9     int8  *insertPos, *extractPos;
    1.10     int8  *oldStartOfData, *oldEndOfData, *newStartOfData, *newEndOfData;
    1.11 -   int8  *insertOffsetBytes, *extractOffsetBytes;
    1.12 +   int32  insertOffsetBytes, extractOffsetBytes;
    1.13 +   int8  *copyStartAddr;
    1.14  
    1.15     oldStartOfData = (int8 *)Q->startOfData;
    1.16     oldEndOfData   = (int8 *)Q->endOfData;
    1.17 @@ -53,10 +54,10 @@
    1.18     extractPos     = (int8 *)Q->extractPos;
    1.19     
    1.20        //TODO: verify these get number of bytes correct
    1.21 -   insertOffsetBytes  = insertPos  - oldStartOfData;
    1.22 -   extractOffsetBytes = extractPos - oldStartOfData);
    1.23 +   insertOffsetBytes  = (int32)(insertPos  - oldStartOfData);
    1.24 +   extractOffsetBytes = (int32)(extractPos - oldStartOfData);
    1.25     
    1.26 -   oldSize            = endOfData  - startOfData + 1; //in bytes
    1.27 +   oldSize            = oldEndOfData - oldStartOfData + 1; //in bytes
    1.28     newSize            = 2 * oldSize;
    1.29     
    1.30        //This malloc is not safe to use in wrapper lib nor app code!
    1.31 @@ -75,7 +76,7 @@
    1.32        //UNLESS the one case where old extract was at bottom and insert
    1.33        // was at top.
    1.34        //TODO: check that this is correct!
    1.35 -   if( extractPos == startOfData && insertPos == endOfData )
    1.36 +   if( extractPos == oldStartOfData && insertPos == oldEndOfData )
    1.37      {
    1.38        memcpy( newStartOfData, oldStartOfData, oldSize ); //oldSize is bytes
    1.39        Q->extractPos  = Q->startOfData; //start of valid data
    1.40 @@ -83,16 +84,16 @@
    1.41      }
    1.42     else //have to copy two parts separately, then calc positions
    1.43      {    //TODO: check end-addr, sizes, and new positions carefully
    1.44 -	
    1.45 +
    1.46           //copy top part, starting at extract up until end of data,
    1.47 -		 // into top of new array
    1.48 +         // into top of new array
    1.49        topPartSize = oldEndOfData - extractPos + 1; //+1 includes extractPos
    1.50 -	  copyStartAddr = newEndOfData - topPartSize + 1;//+1 cancels other
    1.51 +      copyStartAddr = newEndOfData - topPartSize + 1;//+1 cancels other
    1.52        memcpy( copyStartAddr, Q->extractPos, topPartSize );
    1.53 -	  Q->extractPos = (void **)copyStartAddr; //extract just-copied data
    1.54 -	  
    1.55 +      Q->extractPos = (void **)copyStartAddr; //extract just-copied data
    1.56 +  
    1.57           //copy bottom part, from old start up to old insert,
    1.58 -		 // into bottom of new array		 
    1.59 +         // into bottom of new array		 
    1.60        bottPartSize  = oldSize - topPartSize - 1; //-1 for empty insertPos
    1.61        memcpy( newStartOfData, oldStartOfData, bottPartSize );
    1.62        Q->insertPos  = (void **)(newStartOfData + bottPartSize);
    1.63 @@ -163,7 +164,8 @@
    1.64  /*Returns false when the queue was full.
    1.65   * have option of calling make_larger_PrivQ to make more room, then try again
    1.66   */
    1.67 -int writeIfSpacePrivQ( void * in, PrivQueueStruc* Q )
    1.68 +bool32
    1.69 +writeIfSpacePrivQ( void * in, PrivQueueStruc* Q )
    1.70   {
    1.71     void **startOfData = Q->startOfData;
    1.72     void **endOfData   = Q->endOfData;