comparison BlockingQueue.h @ 5:228ca5487d81

Tested and working on full VMS test
author Me
date Wed, 30 Jun 2010 14:35:04 -0700
parents 85af604dee9b
children 08f0b4da7610
comparison
equal deleted inserted replaced
0:9bfdd4f4db12 1:db925ce5603c
1 /* 1 /*
2 * Copyright 2009 OpenSourceStewardshipFoundation.org 2 * File: BlockingQueue.h
3 * Licensed under GNU General Public License version 2 3 * Author: SeanHalle@yahoo.com
4 * 4 *
5 * Author: seanhalle@yahoo.com 5 * Created on November 11, 2009, 12:51 PM
6 */ 6 */
7 7
8 #ifndef _BLOCKING_QUEUE_H 8 #ifndef _BLOCKINGQUEUE_H
9 #define _BLOCKING_QUEUE_H 9 #define _BLOCKINGQUEUE_H
10 10
11 #include <pthread.h> 11 #include "pthread.h"
12 12
13 #define TRUE 1 13
14 #define FALSE 0 14 #define TRUE 1
15 #define FALSE 0
15 16
16 #define LOCKED 1 17 #define LOCKED 1
17 #define UNLOCKED 0 18 #define UNLOCKED 0
18 19
19 20
21 //========== pThreads based queue ==========
20 /* It is the data that is shared so only need one mutex. */ 22 /* It is the data that is shared so only need one mutex. */
21 typedef 23 typedef
22 struct 24 struct
23 { 25 { pthread_mutex_t mutex_t;
24 pthread_mutex_t mutex_t;
25 pthread_cond_t cond_w_t; 26 pthread_cond_t cond_w_t;
26 pthread_cond_t cond_r_t; 27 pthread_cond_t cond_r_t;
27 int count; 28 int count;
28 int readPos; 29 int readPos;
29 int writePos; 30 int writePos;
30 void* data[1024]; //an array of pointers 31 void* data[1024]; //an array of pointers
31 int w_empty; 32 int w_empty;
32 int w_full; 33 int w_full;
33 } 34 }
34 QueueStruc; 35 PThdQueueStruc;
36
37 PThdQueueStruc* makePThdQ();
38 void* readPThdQ( PThdQueueStruc *Q );
39 void writePThdQ( void *in, PThdQueueStruc *Q );
35 40
36 41
42 //========== CAS based queue ==========
37 typedef 43 typedef
38 struct 44 struct
39 { int insertLock; 45 { volatile int insertLock;
40 int extractLock; 46 volatile int extractLock;
41 void* *insertPos; 47 volatile void* *insertPos;
42 void* *extractPos; 48 volatile void* *extractPos;
43 void* startOfData[1024]; //data is pointers 49 void* startOfData[1024]; //data is pointers
44 void* *endOfData; //set when make queue 50 void* *endOfData; //set when make queue
45 } 51 }
46 CASQueueStruc; 52 CASQueueStruc;
47
48
49 typedef
50 struct
51 { void* *insertPos;
52 void* *extractPos;
53 void* startOfData[1024]; //data is pointers
54 void* *endOfData; //set when make queue
55 }
56 SRSWQueueStruc;
57
58
59 QueueStruc* makeQ();
60 void* readQ( QueueStruc *Q );
61 void writeQ( void *in, QueueStruc *Q );
62 53
63 CASQueueStruc* makeCASQ(); 54 CASQueueStruc* makeCASQ();
64 void* readCASQ( CASQueueStruc *Q ); 55 void* readCASQ( CASQueueStruc *Q );
65 void writeCASQ( void *in, CASQueueStruc *Q ); 56 void writeCASQ( void *in, CASQueueStruc *Q );
66 57
58
59 //========= non-atomic instr based queue ===========
60 typedef
61 struct
62 { void* *insertPos;
63 void* *extractPos;
64 void* startOfData[1024]; //data is pointers
65 void* *endOfData; //set when make queue
66 }
67 SRSWQueueStruc;
68
67 SRSWQueueStruc* makeSRSWQ(); 69 SRSWQueueStruc* makeSRSWQ();
68 void* readSRSWQ( SRSWQueueStruc *Q ); 70 void* readSRSWQ( SRSWQueueStruc *Q );
69 void writeSRSWQ( void *in, SRSWQueueStruc *Q ); 71 void writeSRSWQ( void *in, SRSWQueueStruc *Q );
70 72
71 #endif /* _BLOCKING_QUEUE_H */
72 73
74 //========= non-atomic instr S R M W queue ===========
75 typedef
76 struct
77 { int lastQReadFrom;
78 int numInternalQs;
79 int internalQsSz;
80 SRSWQueueStruc* *internalQs;
81 }
82 SRMWQueueStruc;
83
84 SRMWQueueStruc* makeSRMWQ();
85 int addWriterToSRMWQ( SRMWQueueStruc *Q );
86 void* readSRMWQ( SRMWQueueStruc *Q );
87 void writeSRMWQ( void *in, SRMWQueueStruc *Q, int writerID );
88
89
90 #endif /* _BLOCKINGQUEUE_H */
91