changeset 5:228ca5487d81

Tested and working on full VMS test
author Me
date Wed, 30 Jun 2010 14:35:04 -0700
parents 8abcca1590b8
children 174a7c2ca340
files BlockingQueue.h
diffstat 1 files changed, 91 insertions(+), 72 deletions(-) [+]
line diff
     1.1 --- a/BlockingQueue.h	Wed Jun 30 14:34:56 2010 -0700
     1.2 +++ b/BlockingQueue.h	Wed Jun 30 14:35:04 2010 -0700
     1.3 @@ -1,72 +1,91 @@
     1.4 -/*
     1.5 - *  Copyright 2009 OpenSourceStewardshipFoundation.org
     1.6 - *  Licensed under GNU General Public License version 2
     1.7 - *
     1.8 - * Author: seanhalle@yahoo.com
     1.9 - */
    1.10 -
    1.11 -#ifndef _BLOCKING_QUEUE_H
    1.12 -#define	_BLOCKING_QUEUE_H
    1.13 -
    1.14 -#include <pthread.h>
    1.15 -
    1.16 -#define TRUE     1
    1.17 -#define FALSE    0
    1.18 -
    1.19 -#define LOCKED   1
    1.20 -#define UNLOCKED 0
    1.21 -
    1.22 -
    1.23 -/* It is the data that is shared so only need one mutex. */
    1.24 -typedef
    1.25 -struct
    1.26 - {
    1.27 -   pthread_mutex_t  mutex_t;
    1.28 -   pthread_cond_t   cond_w_t;
    1.29 -   pthread_cond_t   cond_r_t;
    1.30 -   int              count;
    1.31 -   int              readPos;
    1.32 -   int              writePos;
    1.33 -   void*            data[1024];  //an array of pointers
    1.34 -   int w_empty;
    1.35 -   int w_full;
    1.36 - }
    1.37 -QueueStruc;
    1.38 -
    1.39 -
    1.40 -typedef
    1.41 -struct
    1.42 - { int              insertLock;
    1.43 -   int              extractLock;
    1.44 -   void*           *insertPos;
    1.45 -   void*           *extractPos;
    1.46 -   void*            startOfData[1024];  //data is pointers
    1.47 -   void*           *endOfData;          //set when make queue
    1.48 - }
    1.49 -CASQueueStruc;
    1.50 -
    1.51 -
    1.52 -typedef
    1.53 -struct
    1.54 - { void*           *insertPos;
    1.55 -   void*           *extractPos;
    1.56 -   void*            startOfData[1024];  //data is pointers
    1.57 -   void*           *endOfData;          //set when make queue
    1.58 - }
    1.59 -SRSWQueueStruc;
    1.60 -
    1.61 -
    1.62 -QueueStruc*     makeQ();
    1.63 -void* readQ( QueueStruc *Q );
    1.64 -void writeQ( void *in, QueueStruc *Q );
    1.65 -
    1.66 -CASQueueStruc*  makeCASQ();
    1.67 -void* readCASQ( CASQueueStruc *Q );
    1.68 -void writeCASQ( void *in, CASQueueStruc *Q );
    1.69 -
    1.70 -SRSWQueueStruc* makeSRSWQ();
    1.71 -void* readSRSWQ( SRSWQueueStruc *Q );
    1.72 -void writeSRSWQ( void *in, SRSWQueueStruc *Q );
    1.73 -
    1.74 -#endif	/* _BLOCKING_QUEUE_H */
    1.75 -
    1.76 +/* 
    1.77 + * File:   BlockingQueue.h
    1.78 + * Author: SeanHalle@yahoo.com
    1.79 + *
    1.80 + * Created on November 11, 2009, 12:51 PM
    1.81 + */
    1.82 +
    1.83 +#ifndef _BLOCKINGQUEUE_H
    1.84 +#define	_BLOCKINGQUEUE_H
    1.85 +
    1.86 +#include "pthread.h"
    1.87 +
    1.88 +
    1.89 +#define TRUE  1
    1.90 +#define FALSE 0
    1.91 +
    1.92 +#define LOCKED   1
    1.93 +#define UNLOCKED 0
    1.94 +
    1.95 +
    1.96 +//========== pThreads based queue ==========
    1.97 +/* It is the data that is shared so only need one mutex. */
    1.98 +typedef
    1.99 +struct
   1.100 + { pthread_mutex_t  mutex_t;
   1.101 +   pthread_cond_t   cond_w_t;
   1.102 +   pthread_cond_t   cond_r_t;
   1.103 +   int              count;
   1.104 +   int              readPos;
   1.105 +   int              writePos;
   1.106 +   void*            data[1024];  //an array of pointers
   1.107 +   int w_empty;
   1.108 +   int w_full;
   1.109 + }
   1.110 +PThdQueueStruc;
   1.111 +
   1.112 +PThdQueueStruc*     makePThdQ();
   1.113 +void* readPThdQ( PThdQueueStruc *Q );
   1.114 +void writePThdQ( void *in, PThdQueueStruc *Q );
   1.115 +
   1.116 +
   1.117 +//========== CAS based queue ==========
   1.118 +typedef
   1.119 +struct
   1.120 + { volatile int     insertLock;
   1.121 +   volatile int     extractLock;
   1.122 +   volatile void*  *insertPos;
   1.123 +   volatile void*  *extractPos;
   1.124 +   void*   startOfData[1024];  //data is pointers
   1.125 +   void*  *endOfData;          //set when make queue
   1.126 + }
   1.127 +CASQueueStruc;
   1.128 +
   1.129 +CASQueueStruc*  makeCASQ();
   1.130 +void* readCASQ( CASQueueStruc *Q );
   1.131 +void writeCASQ( void *in, CASQueueStruc *Q );
   1.132 +
   1.133 +
   1.134 +//========= non-atomic instr based queue ===========
   1.135 +typedef
   1.136 +struct
   1.137 + { void*  *insertPos;
   1.138 +   void*  *extractPos;
   1.139 +   void*   startOfData[1024];  //data is pointers
   1.140 +   void*  *endOfData;          //set when make queue
   1.141 + }
   1.142 +SRSWQueueStruc;
   1.143 +
   1.144 +SRSWQueueStruc* makeSRSWQ();
   1.145 +void* readSRSWQ( SRSWQueueStruc *Q );
   1.146 +void writeSRSWQ( void *in, SRSWQueueStruc *Q );
   1.147 +
   1.148 +
   1.149 +//========= non-atomic instr S R M W queue ===========
   1.150 +typedef
   1.151 +struct
   1.152 + { int              lastQReadFrom;
   1.153 +   int              numInternalQs;
   1.154 +   int              internalQsSz;
   1.155 +   SRSWQueueStruc* *internalQs;
   1.156 + }
   1.157 +SRMWQueueStruc;
   1.158 +
   1.159 +SRMWQueueStruc* makeSRMWQ();
   1.160 +int addWriterToSRMWQ( SRMWQueueStruc *Q );
   1.161 +void* readSRMWQ( SRMWQueueStruc *Q );
   1.162 +void writeSRMWQ( void *in, SRMWQueueStruc *Q, int writerID );
   1.163 +
   1.164 +
   1.165 +#endif	/* _BLOCKINGQUEUE_H */
   1.166 +