1 | /*************************************************************************************** |
---|
2 | * SAGE - Scalable Adaptive Graphics Environment |
---|
3 | * |
---|
4 | * Module: sageBlockQueue.h |
---|
5 | * Author : Byungil Jeong |
---|
6 | * |
---|
7 | * Description: Queue for event driven control in a SAGE component |
---|
8 | * |
---|
9 | * Copyright (C) 2004 Electronic Visualization Laboratory, |
---|
10 | * University of Illinois at Chicago |
---|
11 | * |
---|
12 | * All rights reserved. |
---|
13 | * |
---|
14 | * Redistribution and use in source and binary forms, with or without |
---|
15 | * modification, are permitted provided that the following conditions are met: |
---|
16 | * |
---|
17 | * * Redistributions of source code must retain the above copyright |
---|
18 | * notice, this list of conditions and the following disclaimer. |
---|
19 | * * Redistributions in binary form must reproduce the above |
---|
20 | * copyright notice, this list of conditions and the following disclaimer |
---|
21 | * in the documentation and/or other materials provided with the distribution. |
---|
22 | * * Neither the name of the University of Illinois at Chicago nor |
---|
23 | * the names of its contributors may be used to endorse or promote |
---|
24 | * products derived from this software without specific prior written permission. |
---|
25 | * |
---|
26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
27 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
28 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
29 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
---|
30 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
---|
31 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
32 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
---|
33 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
---|
34 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
---|
35 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
36 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
37 | * |
---|
38 | * Direct questions, comments etc about SAGE to sage_users@listserv.uic.edu or |
---|
39 | * http://www.evl.uic.edu/cavern/forum/ |
---|
40 | * |
---|
41 | *****************************************************************************************/ |
---|
42 | |
---|
43 | #ifndef _SAGE_BLOCK_QUEUE_H |
---|
44 | #define _SAGE_BLOCK_QUEUE_H |
---|
45 | |
---|
46 | #include "sageBase.h" |
---|
47 | |
---|
48 | class sageBlock; |
---|
49 | |
---|
50 | class sageBlockContainer { |
---|
51 | public: |
---|
52 | sageBlock *block; |
---|
53 | sageBlockContainer *next; |
---|
54 | int rcnt; |
---|
55 | |
---|
56 | sageBlockContainer() : block(NULL), next(NULL), rcnt(0) {} |
---|
57 | }; |
---|
58 | |
---|
59 | class sageBlockQueue { |
---|
60 | protected: |
---|
61 | sageBlockContainer *head, *tail; |
---|
62 | sageBlockContainer invalid; |
---|
63 | sageBlockContainer *pointerList[MAX_ENDPOINT_NUM]; |
---|
64 | |
---|
65 | pthread_mutex_t *queueLock; |
---|
66 | pthread_cond_t *notFull; |
---|
67 | |
---|
68 | pthread_mutex_t *listLock; |
---|
69 | pthread_cond_t *notEmpty; |
---|
70 | |
---|
71 | int maxLen, curLen, pointerNum, maxPointerID; |
---|
72 | bool full; |
---|
73 | |
---|
74 | int lastFrame[MAX_ENDPOINT_NUM]; |
---|
75 | int skipFrame[MAX_ENDPOINT_NUM]; |
---|
76 | bool active; |
---|
77 | int montageID; |
---|
78 | bool pixelPassed; |
---|
79 | int lastPixelFrame[MAX_ENDPOINT_NUM]; |
---|
80 | |
---|
81 | public: |
---|
82 | sageBlockQueue(int len = 2); |
---|
83 | ~sageBlockQueue(); |
---|
84 | |
---|
85 | int getLastFrame(int id = 0) { return lastFrame[id]; } |
---|
86 | bool isActive() { return active; } |
---|
87 | void setMonID(int id) { montageID = id; } |
---|
88 | int getMonID() { return montageID; } |
---|
89 | |
---|
90 | void setMaxLen(int len) { maxLen = len; } |
---|
91 | int addReader(int id = 0); |
---|
92 | int removeReader(int id, pthread_mutex_t &lock); |
---|
93 | |
---|
94 | sageBlock* deque(int frame, bool activeMode, int id = 0); |
---|
95 | void enque(sageBlock* block); |
---|
96 | //sageBlock* searchBlock(int x, int y); |
---|
97 | void skipBlocks(int frame, int id = 0); |
---|
98 | |
---|
99 | void initCondVar(pthread_mutex_t *lock, pthread_cond_t *cond); |
---|
100 | bool isEmpty() { return (head == NULL); } |
---|
101 | void clear(); |
---|
102 | }; |
---|
103 | |
---|
104 | class blockQueueList { |
---|
105 | protected: |
---|
106 | std::vector<sageBlockQueue*> queueList; |
---|
107 | pthread_mutex_t *listLock; |
---|
108 | pthread_cond_t *notEmpty; |
---|
109 | |
---|
110 | public: |
---|
111 | blockQueueList(); |
---|
112 | int addQueue(sageBlockQueue *q); |
---|
113 | sageBlockQueue* operator[](int id); |
---|
114 | blockQueueList& operator=(blockQueueList &list); |
---|
115 | int waitForData(); |
---|
116 | void stopWaiting(); |
---|
117 | int size() { return queueList.size(); } |
---|
118 | ~blockQueueList(); |
---|
119 | }; |
---|
120 | |
---|
121 | #endif |
---|