Mercurial > cgi-bin > hgwebdir.cgi > VMS > C_Libraries > Queue_impl
changeset 49:083298a6f7b6 PR_univ_lib
new branch PR_univ_lib -- creates a static library, copied to /usr/lib/PR__lib
author | Sean Halle <seanhalle@yahoo.com> |
---|---|
date | Sat, 27 Jul 2013 13:10:10 -0700 |
parents | 1ea30ca7093c |
children | 93a5782d064b |
files | BlockingQueue.c BlockingQueue.h PrivateQueue.c PrivateQueue.h __brch__PR_univ_lib __brch__Univ_dev prqueue.h |
diffstat | 7 files changed, 148 insertions(+), 106 deletions(-) [+] |
line diff
1.1 --- a/BlockingQueue.c Tue Jul 23 07:28:22 2013 -0700 1.2 +++ b/BlockingQueue.c Sat Jul 27 13:10:10 2013 -0700 1.3 @@ -14,13 +14,32 @@ 1.4 #include <string.h> 1.5 1.6 #include "BlockingQueue.h" 1.7 -#include "PR__common_includes/Services_offered_by_PR/Memory_Handling/vmalloc__wrapper_library.h" 1.8 +#include <PR__include/prqueue.h> 1.9 +#include <PR__include/prmalloc.h> 1.10 1.11 #define INC(x) (++x == 1024) ? (x) = 0 : (x) 1.12 1.13 #define SPINLOCK_TRIES 100000 1.14 1.15 1.16 +//========================== pthread based queue ========================= 1.17 +/*Not currently implemented.. however, copied this code from place where 1.18 + * did equivalent.. Idea is to just make a private queue, then protect 1.19 + * access with a lock.. copied code snippet below is how access was 1.20 + * protected.. just roll this inside a "readBlockingQ()" function.. do 1.21 + * equivalent inside writeBlockingQ() function.. to make one, just add 1.22 + * the lock to the queue structure.. 1.23 + */ 1.24 +/* 1.25 + production = NULL; 1.26 + while( production == NULL ) 1.27 + { pthread_mutex_lock( &queueAccessLock ); 1.28 + production = readPrivQ( commQ ); 1.29 + pthread_mutex_unlock( &queueAccessLock ); 1.30 + // If empty, yields and tries again. 1.31 + if( production == NULL) sched_yield(); 1.32 + } 1.33 +*/ 1.34 1.35 //=========================================================================== 1.36 // multi reader multi writer fast Q via CAS 1.37 @@ -36,7 +55,7 @@ 1.38 CASQueueStruc* makeCASQ() 1.39 { 1.40 CASQueueStruc* retQ; 1.41 - retQ = (CASQueueStruc *) PR_WL__malloc( sizeof( CASQueueStruc ) ); 1.42 + retQ = (CASQueueStruc *) PR__malloc( sizeof( CASQueueStruc ) ); 1.43 1.44 retQ->insertLock = UNLOCKED; 1.45 retQ->extractLock= UNLOCKED; 1.46 @@ -161,7 +180,7 @@ 1.47 SRSWQueueStruc* makeSRSWQ() 1.48 { 1.49 SRSWQueueStruc* retQ; 1.50 - retQ = (SRSWQueueStruc *) PR_WL__malloc( sizeof( SRSWQueueStruc ) ); 1.51 + retQ = (SRSWQueueStruc *) PR__malloc( sizeof( SRSWQueueStruc ) ); 1.52 memset( retQ->startOfData, 0, 1024 * sizeof(void *) ); 1.53 1.54 retQ->extractPos = &(retQ->startOfData[0]); //side by side == empty 1.55 @@ -300,11 +319,11 @@ 1.56 SRMWQueueStruc* makeSRMWQ() 1.57 { SRMWQueueStruc* retQ; 1.58 1.59 - retQ = (SRMWQueueStruc *) PR_WL__malloc( sizeof( SRMWQueueStruc ) ); 1.60 + retQ = (SRMWQueueStruc *) PR__malloc( sizeof( SRMWQueueStruc ) ); 1.61 1.62 retQ->numInternalQs = 0; 1.63 retQ->internalQsSz = 10; 1.64 - retQ->internalQs = PR_WL__malloc( retQ->internalQsSz * sizeof(SRSWQueueStruc *)); 1.65 + retQ->internalQs = PR__malloc( retQ->internalQsSz * sizeof(SRSWQueueStruc *)); 1.66 1.67 retQ->lastQReadFrom = 0; 1.68 1.69 @@ -330,7 +349,7 @@ 1.70 oldSz = Q->internalQsSz; 1.71 oldArray = Q->internalQs; 1.72 Q->internalQsSz *= 2; 1.73 - Q->internalQs = PR_WL__malloc( Q->internalQsSz * sizeof(SRSWQueueStruc *)); 1.74 + Q->internalQs = PR__malloc( Q->internalQsSz * sizeof(SRSWQueueStruc *)); 1.75 for( i = 0; i < oldSz; i++ ) 1.76 { Q->internalQs[i] = oldArray[i]; 1.77 }
2.1 --- a/BlockingQueue.h Tue Jul 23 07:28:22 2013 -0700 2.2 +++ b/BlockingQueue.h Sat Jul 27 13:10:10 2013 -0700 2.3 @@ -8,7 +8,8 @@ 2.4 #ifndef _BLOCKINGQUEUE_H 2.5 #define _BLOCKINGQUEUE_H 2.6 2.7 -#include "PR__common_includes/PR__primitive_data_types.h" 2.8 +#include <PR__include/PR__primitive_data_types.h> 2.9 +#include <PR__include/prmalloc.h> 2.10 2.11 2.12 #define TRUE 1 2.13 @@ -17,76 +18,5 @@ 2.14 #define LOCKED 1 2.15 #define UNLOCKED 0 2.16 2.17 - 2.18 -//========== pThreads based queue ========== 2.19 -/* It is the data that is shared so only need one mutex. */ 2.20 -typedef 2.21 -struct 2.22 - { pthread_mutex_t mutex_t; 2.23 - pthread_cond_t cond_w_t; 2.24 - pthread_cond_t cond_r_t; 2.25 - int32 count; 2.26 - int32 readPos; 2.27 - int32 writePos; 2.28 - void* data[1024]; //an array of pointers 2.29 - int w_empty; 2.30 - int w_full; 2.31 - } 2.32 -PThdQueueStruc; 2.33 - 2.34 -PThdQueueStruc* makePThdQ(); 2.35 -void* readPThdQ( PThdQueueStruc *Q ); 2.36 -void writePThdQ( void *in, PThdQueueStruc *Q ); 2.37 - 2.38 - 2.39 -//========== CAS based queue ========== 2.40 -typedef 2.41 -struct 2.42 - { volatile int32 insertLock; 2.43 - volatile int32 extractLock; 2.44 - volatile void* *insertPos; 2.45 - volatile void* *extractPos; 2.46 - void* startOfData[1024]; //data is pointers 2.47 - void* *endOfData; //set when make queue 2.48 - } 2.49 -CASQueueStruc; 2.50 - 2.51 -CASQueueStruc* makeCASQ(); 2.52 -void* readCASQ( CASQueueStruc *Q ); 2.53 -void writeCASQ( void *in, CASQueueStruc *Q ); 2.54 - 2.55 - 2.56 -//========= non-atomic instr based queue =========== 2.57 -typedef 2.58 -struct 2.59 - { void* *insertPos; 2.60 - void* *extractPos; 2.61 - void* startOfData[1024]; //data is pointers 2.62 - void* *endOfData; //set when make queue 2.63 - } 2.64 -SRSWQueueStruc; 2.65 - 2.66 -SRSWQueueStruc* makeSRSWQ(); 2.67 -void freeSRSWQ( SRSWQueueStruc* Q ); 2.68 -void* readSRSWQ( SRSWQueueStruc *Q ); 2.69 -void writeSRSWQ( void *in, SRSWQueueStruc *Q ); 2.70 - 2.71 - 2.72 -//========= non-atomic instr S R M W queue =========== 2.73 -typedef 2.74 -struct 2.75 - { int32 lastQReadFrom; 2.76 - int32 numInternalQs; 2.77 - int32 internalQsSz; 2.78 - SRSWQueueStruc* *internalQs; 2.79 - } 2.80 -SRMWQueueStruc; 2.81 - 2.82 -SRMWQueueStruc* makeSRMWQ(); 2.83 -int addWriterToSRMWQ( SRMWQueueStruc *Q ); 2.84 -void* readSRMWQ( SRMWQueueStruc *Q ); 2.85 -void writeSRMWQ( void *in, SRMWQueueStruc *Q, int writerID ); 2.86 - 2.87 - 2.88 #endif /* _BLOCKINGQUEUE_H */ 2.89
3.1 --- a/PrivateQueue.c Tue Jul 23 07:28:22 2013 -0700 3.2 +++ b/PrivateQueue.c Sat Jul 27 13:10:10 2013 -0700 3.3 @@ -14,7 +14,8 @@ 3.4 #include <stdlib.h> 3.5 3.6 #include "PrivateQueue.h" 3.7 -#include "PR__common_includes/Services_offered_by_PR/Memory_Handling/vmalloc__wrapper_library.h" 3.8 +#include <PR__include/prqueue.h> 3.9 +#include <PR__include/prmalloc.h> 3.10 3.11 3.12
4.1 --- a/PrivateQueue.h Tue Jul 23 07:28:22 2013 -0700 4.2 +++ b/PrivateQueue.h Sat Jul 27 13:10:10 2013 -0700 4.3 @@ -8,7 +8,7 @@ 4.4 #ifndef _PRIVATE_QUEUE_H 4.5 #define _PRIVATE_QUEUE_H 4.6 4.7 -#include "PR__common_includes/PR__primitive_data_types.h" 4.8 +#include <PR__include/PR__primitive_data_types.h> 4.9 4.10 #define TRUE 1 4.11 #define FALSE 0 4.12 @@ -17,27 +17,5 @@ 4.13 #define UNLOCKED 0 4.14 4.15 4.16 -/* It is the data that is shared so only need one mutex. */ 4.17 -typedef struct 4.18 - { void **insertPos; 4.19 - void **extractPos; 4.20 - void **startOfData; //data is pointers 4.21 - void **endOfData; //set when alloc data 4.22 - } 4.23 -PrivQueueStruc; 4.24 - 4.25 -typedef void (*DynArrayFnPtr) ( void * ); //fn has to cast void * 4.26 - 4.27 -PrivQueueStruc* makePrivQ ( ); 4.28 -bool32 isEmptyPrivQ ( PrivQueueStruc *Q ); //ret TRUE if empty 4.29 -void* peekPrivQ ( PrivQueueStruc *Q ); //ret NULL if empty 4.30 -void* readPrivQ ( PrivQueueStruc *Q ); //ret NULL if empty 4.31 -void writePrivQ( void *in, PrivQueueStruc *Q ); 4.32 - //return false when full 4.33 -bool32 writeIfSpacePrivQ( void * in, PrivQueueStruc* Q ); 4.34 -int32 numInPrivQ( PrivQueueStruc *Q ); 4.35 -void pushPrivQ( void * in, PrivQueueStruc* Q ); 4.36 -void freePrivQ( PrivQueueStruc *Q ); 4.37 - 4.38 #endif /* _PRIVATE_QUEUE_H */ 4.39
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/__brch__PR_univ_lib Sat Jul 27 13:10:10 2013 -0700 5.3 @@ -0,0 +1,4 @@ 5.4 +This branch is for developing the queues used by proto-runtime code.. and packaging as a static library. 5.5 + 5.6 + 5.7 +
6.1 --- a/__brch__Univ_dev Tue Jul 23 07:28:22 2013 -0700 6.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 6.3 @@ -1,4 +0,0 @@ 6.4 -This branch is for the project structure defined Jan 2012.. the #includes reflect this directory structure. 6.5 - 6.6 -More importantly, the MC_shared version of PR requires a separat malloc implemeted by PR code.. so this branch has modified the library to use the PR-specific malloc. 6.7 -
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/prqueue.h Sat Jul 27 13:10:10 2013 -0700 7.3 @@ -0,0 +1,114 @@ 7.4 +/* 7.5 + * Copyright 2009 OpenSourceResearchInstitute.org 7.6 + * Licensed under GNU General Public License version 2 7.7 + * 7.8 + * Author: seanhalle@yahoo.com 7.9 + */ 7.10 + 7.11 +#ifndef _PRQUEUE_H 7.12 +#define _PRQUEUE_H 7.13 + 7.14 +#include <PR__include/PR__primitive_data_types.h> 7.15 +#include <pthread.h> 7.16 + 7.17 +#define TRUE 1 7.18 +#define FALSE 0 7.19 + 7.20 +//================== Private Queue stuff =================== 7.21 +/* It is the data that is shared so only need one mutex. */ 7.22 +typedef struct 7.23 + { void **insertPos; 7.24 + void **extractPos; 7.25 + void **startOfData; //data is pointers 7.26 + void **endOfData; //set when alloc data 7.27 + } 7.28 +PrivQueueStruc; 7.29 + 7.30 +typedef void (*DynArrayFnPtr) ( void * ); //fn has to cast void * 7.31 + 7.32 +PrivQueueStruc* makePrivQ ( ); 7.33 +bool32 isEmptyPrivQ ( PrivQueueStruc *Q ); //ret TRUE if empty 7.34 +void* peekPrivQ ( PrivQueueStruc *Q ); //ret NULL if empty 7.35 +void* readPrivQ ( PrivQueueStruc *Q ); //ret NULL if empty 7.36 +void writePrivQ( void *in, PrivQueueStruc *Q ); 7.37 + //return false when full 7.38 +bool32 writeIfSpacePrivQ( void * in, PrivQueueStruc* Q ); 7.39 +int32 numInPrivQ( PrivQueueStruc *Q ); 7.40 +void pushPrivQ( void * in, PrivQueueStruc* Q ); 7.41 +void freePrivQ( PrivQueueStruc *Q ); 7.42 + 7.43 + 7.44 +//====================== Parallel Queue Stuff ==================== 7.45 + 7.46 +//========== pThreads based queue ========== 7.47 +/* It is the data that is shared so only need one mutex. */ 7.48 +typedef 7.49 +struct 7.50 + { pthread_mutex_t mutex_t; 7.51 + pthread_cond_t cond_w_t; 7.52 + pthread_cond_t cond_r_t; 7.53 + int32 count; 7.54 + int32 readPos; 7.55 + int32 writePos; 7.56 + void* data[1024]; //an array of pointers 7.57 + int w_empty; 7.58 + int w_full; 7.59 + } 7.60 +PThdQueueStruc; 7.61 + 7.62 +PThdQueueStruc* makePThdQ(); 7.63 +void* readPThdQ( PThdQueueStruc *Q ); 7.64 +void writePThdQ( void *in, PThdQueueStruc *Q ); 7.65 + 7.66 + 7.67 +//========== CAS based queue ========== 7.68 +typedef 7.69 +struct 7.70 + { volatile int32 insertLock; 7.71 + volatile int32 extractLock; 7.72 + volatile void* *insertPos; 7.73 + volatile void* *extractPos; 7.74 + void* startOfData[1024]; //data is pointers 7.75 + void* *endOfData; //set when make queue 7.76 + } 7.77 +CASQueueStruc; 7.78 + 7.79 +CASQueueStruc* makeCASQ(); 7.80 +void* readCASQ( CASQueueStruc *Q ); 7.81 +void writeCASQ( void *in, CASQueueStruc *Q ); 7.82 + 7.83 + 7.84 +//========= non-atomic instr based queue =========== 7.85 +typedef 7.86 +struct 7.87 + { void* *insertPos; 7.88 + void* *extractPos; 7.89 + void* startOfData[1024]; //data is pointers 7.90 + void* *endOfData; //set when make queue 7.91 + } 7.92 +SRSWQueueStruc; 7.93 + 7.94 +SRSWQueueStruc* makeSRSWQ(); 7.95 +void freeSRSWQ( SRSWQueueStruc* Q ); 7.96 +void* readSRSWQ( SRSWQueueStruc *Q ); 7.97 +void writeSRSWQ( void *in, SRSWQueueStruc *Q ); 7.98 + 7.99 + 7.100 +//========= non-atomic instr S R M W queue =========== 7.101 +typedef 7.102 +struct 7.103 + { int32 lastQReadFrom; 7.104 + int32 numInternalQs; 7.105 + int32 internalQsSz; 7.106 + SRSWQueueStruc* *internalQs; 7.107 + } 7.108 +SRMWQueueStruc; 7.109 + 7.110 +SRMWQueueStruc* makeSRMWQ(); 7.111 +int addWriterToSRMWQ( SRMWQueueStruc *Q ); 7.112 +void* readSRMWQ( SRMWQueueStruc *Q ); 7.113 +void writeSRMWQ( void *in, SRMWQueueStruc *Q, int writerID ); 7.114 + 7.115 + 7.116 +#endif /* _PRIVATE_QUEUE_H */ 7.117 +