# HG changeset patch # User SeanHalle # Date 1289477941 28800 # Node ID 3134d8a1e8e39722ab37726cd3a54e34de66cf83 # Parent 3562716ebdbde0fc5e1d23d91cdde57ca2c62caa added pushPrivQ -- treats Q as stack, pushed elem is first out diff -r 3562716ebdbd -r 3134d8a1e8e3 PrivateQueue.c --- a/PrivateQueue.c Thu Nov 04 17:54:08 2010 -0700 +++ b/PrivateQueue.c Thu Nov 11 04:19:01 2010 -0800 @@ -156,6 +156,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 3562716ebdbd -r 3134d8a1e8e3 PrivateQueue.h --- a/PrivateQueue.h Thu Nov 04 17:54:08 2010 -0700 +++ b/PrivateQueue.h Thu Nov 11 04:19:01 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 */