source: Sophya/trunk/ArchTOIPipe/Kernel/toi.cc@ 1480

Last change on this file since 1480 was 1464, checked in by ansari, 24 years ago

1) Fin de passage des flags en int_8
2) TOIRegularWindow mis ds un fichier spare , Reza 11/4/2001

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