changeset 12:3134d8a1e8e3 VMS__malloc_brch

added pushPrivQ -- treats Q as stack, pushed elem is first out
author SeanHalle
date Thu, 11 Nov 2010 04:19:01 -0800
parents 3562716ebdbd
children 1ab93714b9c1
files PrivateQueue.c PrivateQueue.h
diffstat 2 files changed, 34 insertions(+), 2 deletions(-) [+]
line diff
     1.1 --- a/PrivateQueue.c	Thu Nov 04 17:54:08 2010 -0700
     1.2 +++ b/PrivateQueue.c	Thu Nov 11 04:19:01 2010 -0800
     1.3 @@ -156,6 +156,39 @@
     1.4     return FALSE;
     1.5   }
     1.6  
     1.7 +/*Treats queue as a stack -- no matter contents, if read done right after
     1.8 + * a push, then the pushed item is what comes out.
     1.9 + * Expands the queue size automatically when it's full.
    1.10 + */
    1.11 +void
    1.12 +pushPrivQ( void * in, PrivQueueStruc* Q )
    1.13 + {
    1.14 +   void **startOfData = Q->startOfData;
    1.15 +   void **endOfData   = Q->endOfData;
    1.16 +
    1.17 +   void **insertPos  = Q->insertPos;
    1.18 +   void **extractPos = Q->extractPos;
    1.19 +
    1.20 +tryAgain:
    1.21 +      //Full? (insert is just below extract when full)
    1.22 +   if( extractPos - insertPos != 1 &&
    1.23 +       !(insertPos == endOfData && extractPos == startOfData))
    1.24 +    {    //insert -- but go backwards, inserting at read position then
    1.25 +         // move read pos backwards
    1.26 +      *(Q->extractPos) = in;
    1.27 +      if( extractPos == startOfData ) //write new pos exactly once, correctly
    1.28 +       { Q->extractPos = endOfData;   //can't overrun then fix it 'cause
    1.29 +       }                              // other thread might read bad pos
    1.30 +      else
    1.31 +       { Q->extractPos--;
    1.32 +       }
    1.33 +      return;
    1.34 +    }
    1.35 +      //Q is full
    1.36 +   enlargePrivQ( Q );
    1.37 +   goto tryAgain;
    1.38 + }
    1.39 +
    1.40  void
    1.41  freePrivQ( PrivQueueStruc *Q )
    1.42   {
     2.1 --- a/PrivateQueue.h	Thu Nov 04 17:54:08 2010 -0700
     2.2 +++ b/PrivateQueue.h	Thu Nov 11 04:19:01 2010 -0800
     2.3 @@ -8,7 +8,6 @@
     2.4  #ifndef _PRIVATE_QUEUE_H
     2.5  #define	_PRIVATE_QUEUE_H
     2.6  
     2.7 -#include <pthread.h>
     2.8  #include "../VMS_primitive_data_types.h"
     2.9  
    2.10  #define TRUE     1
    2.11 @@ -33,7 +32,7 @@
    2.12  int32            writeIfSpacePrivQ( void * in, PrivQueueStruc* Q ); //return
    2.13                      // false when full
    2.14  int32            numInPrivQ( PrivQueueStruc *Q );
    2.15 -
    2.16 +void             pushPrivQ( void * in, PrivQueueStruc* Q );
    2.17  
    2.18  #endif	/* _PRIVATE_QUEUE_H */
    2.19