annotate prqueue.h @ 21:c05370bd62dd

Raw version of significantly reduced amount of sched_getcpu calls; linked lib_prt commit: 5e2ee79f8d4a
author Philipe Louchtch
date Sun, 15 Jun 2014 13:06:28 +0200
parents c3829f630c2f
children
rev   line source
Philipe@20 1 /*
Philipe@20 2 * Copyright 2009 OpenSourceResearchInstitute.org
Philipe@20 3 * Licensed under GNU General Public License version 2
Philipe@20 4 *
Philipe@20 5 * Author: seanhalle@yahoo.com
Philipe@20 6 */
Philipe@20 7
Philipe@20 8 #ifndef _PRQUEUE_H
Philipe@20 9 #define _PRQUEUE_H
Philipe@20 10
Philipe@20 11 #include <PR__include/PR__primitive_data_types.h>
Philipe@20 12 //#include <pthreads/implement.h> //Part of pthreads-win32, needed for type definitions
Philipe@20 13 #include <PR__include/osportability.h>
Philipe@20 14
Philipe@20 15 #define TRUE 1
Philipe@20 16 #define FALSE 0
Philipe@20 17
Philipe@20 18 //================== Private Queue stuff ===================
Philipe@20 19 /* It is the data that is shared so only need one mutex. */
Philipe@20 20 typedef struct _PrivQueueStruc
Philipe@20 21 { void **insertPos;
Philipe@20 22 void **extractPos;
Philipe@20 23 void **startOfData; //data is pointers
Philipe@20 24 void **endOfData; //set when alloc data
Philipe@20 25 }
Philipe@20 26 PrivQueueStruc;
Philipe@20 27
Philipe@20 28 typedef void (*DynArrayFnPtr) ( void * ); //fn has to cast void *
Philipe@20 29
Philipe@20 30 PrivQueueStruc* makePrivQ ( );
Philipe@20 31 bool32 isEmptyPrivQ ( PrivQueueStruc *Q ); //ret TRUE if empty
Philipe@20 32 void* peekPrivQ ( PrivQueueStruc *Q ); //ret NULL if empty
Philipe@20 33 void* readPrivQ ( PrivQueueStruc *Q ); //ret NULL if empty
Philipe@20 34 void writePrivQ( void *in, PrivQueueStruc *Q );
Philipe@20 35 //return false when full
Philipe@20 36 bool32 writeIfSpacePrivQ( void * in, PrivQueueStruc* Q );
Philipe@20 37 int32 numInPrivQ( PrivQueueStruc *Q );
Philipe@20 38 void pushPrivQ( void * in, PrivQueueStruc* Q );
Philipe@20 39 void freePrivQ( PrivQueueStruc *Q );
Philipe@20 40
Philipe@20 41
Philipe@20 42 //====================== Parallel Queue Stuff ====================
Philipe@20 43
Philipe@20 44 //========== pThreads based queue ==========
Philipe@20 45 /* It is the data that is shared so only need one mutex. */
Philipe@20 46 typedef
Philipe@20 47 struct _PThdQueueStruc
Philipe@20 48 {
Philipe@20 49 pthread_mutex_t mutex_t;
Philipe@20 50 pthread_cond_t cond_w_t;
Philipe@20 51 pthread_cond_t cond_r_t;
Philipe@20 52 int32 count;
Philipe@20 53 int32 readPos;
Philipe@20 54 int32 writePos;
Philipe@20 55 void* data[1024]; //an array of pointers
Philipe@20 56 int w_empty;
Philipe@20 57 int w_full;
Philipe@20 58 }
Philipe@20 59 PThdQueueStruc;
Philipe@20 60
Philipe@20 61 PThdQueueStruc* makePThdQ();
Philipe@20 62 void* readPThdQ( PThdQueueStruc *Q );
Philipe@20 63 void writePThdQ( void *in, PThdQueueStruc *Q );
Philipe@20 64
Philipe@20 65
Philipe@20 66 //========== CAS based queue ==========
Philipe@20 67 typedef
Philipe@20 68 struct _CASQueueStruc
Philipe@20 69 { volatile int32 insertLock;
Philipe@20 70 volatile int32 extractLock;
Philipe@20 71 volatile void* *insertPos;
Philipe@20 72 volatile void* *extractPos;
Philipe@20 73 void* startOfData[1024]; //data is pointers
Philipe@20 74 void* *endOfData; //set when make queue
Philipe@20 75 }
Philipe@20 76 CASQueueStruc;
Philipe@20 77
Philipe@20 78 CASQueueStruc* makeCASQ();
Philipe@20 79 void* readCASQ( CASQueueStruc *Q );
Philipe@20 80 void writeCASQ( void *in, CASQueueStruc *Q );
Philipe@20 81
Philipe@20 82
Philipe@20 83 //========= non-atomic instr based queue ===========
Philipe@20 84 typedef
Philipe@20 85 struct _SRSWQueueStruc
Philipe@20 86 { void* *insertPos;
Philipe@20 87 void* *extractPos;
Philipe@20 88 void* startOfData[1024]; //data is pointers
Philipe@20 89 void* *endOfData; //set when make queue
Philipe@20 90 }
Philipe@20 91 SRSWQueueStruc;
Philipe@20 92
Philipe@20 93 SRSWQueueStruc* makeSRSWQ();
Philipe@20 94 void freeSRSWQ( SRSWQueueStruc* Q );
Philipe@20 95 void* readSRSWQ( SRSWQueueStruc *Q );
Philipe@20 96 void writeSRSWQ( void *in, SRSWQueueStruc *Q );
Philipe@20 97
Philipe@20 98
Philipe@20 99 //========= non-atomic instr S R M W queue ===========
Philipe@20 100 typedef
Philipe@20 101 struct _SRMWQueueStruc
Philipe@20 102 { int32 lastQReadFrom;
Philipe@20 103 int32 numInternalQs;
Philipe@20 104 int32 internalQsSz;
Philipe@20 105 SRSWQueueStruc* *internalQs;
Philipe@20 106 }
Philipe@20 107 SRMWQueueStruc;
Philipe@20 108
Philipe@20 109 SRMWQueueStruc* makeSRMWQ();
Philipe@20 110 int addWriterToSRMWQ( SRMWQueueStruc *Q );
Philipe@20 111 void* readSRMWQ( SRMWQueueStruc *Q );
Philipe@20 112 void writeSRMWQ( void *in, SRMWQueueStruc *Q, int writerID );
Philipe@20 113
Philipe@20 114
Philipe@20 115 #endif /* _PRIVATE_QUEUE_H */
Philipe@20 116