1 | // ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
|
---|
2 | // Eric Aubourg
|
---|
3 | // Christophe Magneville
|
---|
4 | // Reza Ansari
|
---|
5 | // $Id: toi.cc,v 1.8 2001-11-08 23:23:58 aubourg Exp $
|
---|
6 |
|
---|
7 | #include "toiprocessor.h"
|
---|
8 | #include "toi.h"
|
---|
9 | #include <pthread.h>
|
---|
10 |
|
---|
11 | #ifdef WITH_SOPHYA
|
---|
12 | #include "pexceptions.h"
|
---|
13 | #else
|
---|
14 | #include "apexceptions.h"
|
---|
15 | #endif
|
---|
16 |
|
---|
17 |
|
---|
18 | TOI::TOI() {
|
---|
19 | TOIInit();
|
---|
20 | }
|
---|
21 |
|
---|
22 | TOI::TOI(string n) {
|
---|
23 | name = n;
|
---|
24 | TOIInit();
|
---|
25 | }
|
---|
26 |
|
---|
27 | void TOI::TOIInit() {
|
---|
28 | pthread_mutex_init(&mutex, NULL);
|
---|
29 | // ----- Rajouts Reza 12/3/2001
|
---|
30 | pthread_cond_init(&condv, NULL);
|
---|
31 | fgwaitput = fgwaitget = false;
|
---|
32 | fgsigput = fgsigget = false;
|
---|
33 | countwaitput = countwaitget = 0;
|
---|
34 | // Fin rajouts Reza 12/3/2001 ------
|
---|
35 | // pthread_mutex_setname_np(&mutex, (name + "_toi_mutex").c_str(), 0);
|
---|
36 | defaultValue = 0;
|
---|
37 | producer = NULL;
|
---|
38 | dbg = false;
|
---|
39 | syncOldWay = true;
|
---|
40 | }
|
---|
41 |
|
---|
42 | TOI::~TOI() {
|
---|
43 | pthread_mutex_destroy(&mutex);
|
---|
44 | }
|
---|
45 |
|
---|
46 | void TOI::PrintStatus(ostream & os) const
|
---|
47 | {
|
---|
48 | os << "TOI::PrintStatus() - Name=" << getName() << endl;
|
---|
49 | os << " WaitStatus: Put/" ;
|
---|
50 | if (isPutWaiting()) os << "Waiting " ;
|
---|
51 | else os << "Running ";
|
---|
52 | os << " PutCountWait= " << getCountWaitPut() << endl;
|
---|
53 | os << " WaitStatus: Get/" ;
|
---|
54 | if (isGetWaiting()) os << "Waiting " ;
|
---|
55 | else os << "Running ";
|
---|
56 | os << " GetCountWait= " << getCountWaitGet() << endl;
|
---|
57 | }
|
---|
58 |
|
---|
59 |
|
---|
60 | void TOI::setProducer(TOIProcessor* p) {
|
---|
61 | if (producer)
|
---|
62 | throw DuplicateIdExc("TOI::setProducer : producer already defined");
|
---|
63 | producer = p;
|
---|
64 | }
|
---|
65 |
|
---|
66 | void TOI::addConsumer(TOIProcessor* p) {
|
---|
67 | consumers.push_back(p);
|
---|
68 | }
|
---|
69 |
|
---|
70 | int TOI::getMinSn(){
|
---|
71 | return producer->getMinOut();
|
---|
72 | }
|
---|
73 |
|
---|
74 | int TOI::getMaxSn(){
|
---|
75 | return producer->getMaxOut();
|
---|
76 | }
|
---|
77 |
|
---|
78 | /*
|
---|
79 | RZCMV ----- l'interface va etre modifiee, NE PAS UTILISER
|
---|
80 | #ifndef NO_SOPHYA
|
---|
81 | Array TOI::getError(int iStart, int iEnd) {
|
---|
82 | if (errorTOI == NULL) throw NotFoundExc("TOI::getDataError : no Error TOI");
|
---|
83 | return errorTOI->getData(iStart, iEnd);
|
---|
84 | }
|
---|
85 | Array TOI::getData(int iStart, int iEnd) {
|
---|
86 | lock();
|
---|
87 | Array a = doGetData(iStart, iEnd);
|
---|
88 | unlock();
|
---|
89 | if (fgsigput) { fgsigput = false; broadcast(); }
|
---|
90 | return a;
|
---|
91 | }
|
---|
92 | TArray<int_4> TOI::getFlag(int iStart, int iEnd) {
|
---|
93 | lock();
|
---|
94 | TArray<int_4> a = doGetFlag(iStart, iEnd);
|
---|
95 | unlock();
|
---|
96 | if (fgsigput) { fgsigput = false; broadcast(); }
|
---|
97 | return a;
|
---|
98 | }
|
---|
99 | #endif
|
---|
100 | l'interface va etre modifiee, NE PAS UTILISER ----
|
---|
101 | */
|
---|
102 |
|
---|
103 |
|
---|
104 | /*
|
---|
105 | RZCMV ------- A revoir les getError() ...
|
---|
106 | double TOI::getError(int i) {
|
---|
107 | if (errorTOI == NULL) throw NotFoundExc("TOI::getDataError : no Error TOI");
|
---|
108 | return errorTOI->getData(i);
|
---|
109 | }
|
---|
110 |
|
---|
111 | void TOI::putDataError(int i, double value, double error, int_4 flag) {
|
---|
112 | if (errorTOI == NULL) throw NotFoundExc("TOI::getDataError : no Error TOI");
|
---|
113 | putData(i, value, flag);
|
---|
114 | errorTOI->putData(i, value, flag);
|
---|
115 | }
|
---|
116 |
|
---|
117 | */
|
---|
118 |
|
---|
119 | double TOI::getData(int i) {
|
---|
120 | lock();
|
---|
121 | uint_8 flg;
|
---|
122 | double dat;
|
---|
123 | doGetData(i, dat, flg);
|
---|
124 | unlock();
|
---|
125 | if (fgsigput) { fgsigput = false; broadcast(); }
|
---|
126 | return dat;
|
---|
127 | }
|
---|
128 |
|
---|
129 | void TOI::getData(int i, double &data, uint_8 &flag) {
|
---|
130 | lock();
|
---|
131 | doGetData(i, data, flag);
|
---|
132 | unlock();
|
---|
133 | if (fgsigput) { fgsigput = false; broadcast(); }
|
---|
134 | return;
|
---|
135 | }
|
---|
136 |
|
---|
137 |
|
---|
138 |
|
---|
139 | void TOI::putData(int i, double value, uint_8 flag) {
|
---|
140 | lock();
|
---|
141 | doPutData(i, value, flag);
|
---|
142 | unlock();
|
---|
143 | if (fgsigget) { fgsigget = false; broadcast(); }
|
---|
144 | }
|
---|
145 |
|
---|
146 | void TOI::waitForData(int iStart, int iEnd) {
|
---|
147 | if (producer == NULL) throw NotFoundExc("TOI has no producer !");
|
---|
148 |
|
---|
149 | DataStatus s = isDataAvail(iStart, iEnd);
|
---|
150 | if (s == DATA_OK) {
|
---|
151 | return;
|
---|
152 | }
|
---|
153 | if (s == DATA_DELETED) {
|
---|
154 | throw NotFoundExc("Data has been purged !");
|
---|
155 | }
|
---|
156 |
|
---|
157 | producer->lock();
|
---|
158 | while (isDataAvailNL(iStart, iEnd) == DATA_NOT_YET) {
|
---|
159 | producer->wait();
|
---|
160 | }
|
---|
161 | producer->unlock();
|
---|
162 | return;
|
---|
163 | }
|
---|
164 |
|
---|
165 | void TOI::waitForData(int i) {
|
---|
166 | waitForData(i,i);
|
---|
167 | }
|
---|
168 |
|
---|
169 | void TOI::waitForAnyData() {
|
---|
170 | if (! hasSomeData()) {
|
---|
171 | producer->lock();
|
---|
172 | producer->wait();
|
---|
173 | producer->unlock();
|
---|
174 | }
|
---|
175 | }
|
---|
176 |
|
---|
177 | TOI::DataStatus TOI::isDataAvail(int i) {
|
---|
178 | lock();
|
---|
179 | DataStatus stat = isDataAvailNL(i);
|
---|
180 | unlock();
|
---|
181 | return stat;
|
---|
182 | }
|
---|
183 |
|
---|
184 | TOI::DataStatus TOI::isDataAvail(int i, int j) {
|
---|
185 | lock();
|
---|
186 | DataStatus stat = isDataAvailNL(i,j);
|
---|
187 | unlock();
|
---|
188 | return stat;
|
---|
189 | }
|
---|
190 |
|
---|
191 | TOI::DataStatus TOI::isDataAvailNL(int i) {
|
---|
192 | return isDataAvailNL(i,i);
|
---|
193 | }
|
---|
194 |
|
---|
195 | void TOI::wontNeedBefore(int i) {
|
---|
196 | int j=i;
|
---|
197 | for (vector<TOIProcessor*>::iterator k = consumers.begin();
|
---|
198 | k != consumers.end(); k++) {
|
---|
199 | if ((*k)->wontNeedValue < j) j = (*k)->wontNeedValue;
|
---|
200 | }
|
---|
201 | lock();
|
---|
202 | doWontNeedBefore(j);
|
---|
203 | unlock();
|
---|
204 | }
|
---|
205 |
|
---|
206 | void TOI::doWontNeedBefore(int i) {
|
---|
207 | }
|
---|
208 |
|
---|
209 |
|
---|