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

Last change on this file since 1738 was 1738, checked in by aubourg, 24 years ago

copyright

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