# HG changeset patch # User SeanHalle # Date 1289481373 28800 # Node ID 1ab93714b9c1d9270d6c412d8292a98a6bea8997 # Parent 447e97a524269d878920471a741b0d745eae1bcd# Parent 3134d8a1e8e39722ab37726cd3a54e34de66cf83 Merge pushPrivQ into VMS_malloc brch diff -r 447e97a52426 -r 1ab93714b9c1 PrivateQueue.c --- a/PrivateQueue.c Thu Nov 04 17:56:08 2010 -0700 +++ b/PrivateQueue.c Thu Nov 11 05:16:13 2010 -0800 @@ -157,6 +157,39 @@ return FALSE; } +/*Treats queue as a stack -- no matter contents, if read done right after + * a push, then the pushed item is what comes out. + * Expands the queue size automatically when it's full. + */ +void +pushPrivQ( void * in, PrivQueueStruc* Q ) + { + void **startOfData = Q->startOfData; + void **endOfData = Q->endOfData; + + void **insertPos = Q->insertPos; + void **extractPos = Q->extractPos; + +tryAgain: + //Full? (insert is just below extract when full) + if( extractPos - insertPos != 1 && + !(insertPos == endOfData && extractPos == startOfData)) + { //insert -- but go backwards, inserting at read position then + // move read pos backwards + *(Q->extractPos) = in; + if( extractPos == startOfData ) //write new pos exactly once, correctly + { Q->extractPos = endOfData; //can't overrun then fix it 'cause + } // other thread might read bad pos + else + { Q->extractPos--; + } + return; + } + //Q is full + enlargePrivQ( Q ); + goto tryAgain; + } + void freePrivQ( PrivQueueStruc *Q ) { diff -r 447e97a52426 -r 1ab93714b9c1 PrivateQueue.h --- a/PrivateQueue.h Thu Nov 04 17:56:08 2010 -0700 +++ b/PrivateQueue.h Thu Nov 11 05:16:13 2010 -0800 @@ -8,7 +8,6 @@ #ifndef _PRIVATE_QUEUE_H #define _PRIVATE_QUEUE_H -#include #include "../VMS_primitive_data_types.h" #define TRUE 1 @@ -33,7 +32,7 @@ int32 writeIfSpacePrivQ( void * in, PrivQueueStruc* Q ); //return // false when full int32 numInPrivQ( PrivQueueStruc *Q ); - +void pushPrivQ( void * in, PrivQueueStruc* Q ); #endif /* _PRIVATE_QUEUE_H */