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

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

toujours et encore magique

File size: 5.0 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.11 2001-11-13 16:22:47 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 syncOldWay = true;
40}
41
42TOI::~TOI() {
43 pthread_mutex_destroy(&mutex);
44}
45
46void 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
60void TOI::setProducer(TOIProcessor* p) {
61 if (producer)
62 throw DuplicateIdExc("TOI::setProducer : producer already defined");
63 producer = p;
64}
65
66void TOI::addConsumer(TOIProcessor* p) {
67 consumers.push_back(p);
68}
69
70int TOI::getMinSn(){
71 return producer->getMinOut();
72}
73
74int TOI::getMaxSn(){
75 return producer->getMaxOut();
76}
77
78/*
79 RZCMV ----- l'interface va etre modifiee, NE PAS UTILISER
80#ifndef NO_SOPHYA
81Array TOI::getError(int iStart, int iEnd) {
82 if (errorTOI == NULL) throw NotFoundExc("TOI::getDataError : no Error TOI");
83 return errorTOI->getData(iStart, iEnd);
84}
85Array 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}
92TArray<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/*
105RZCMV ------- A revoir les getError() ...
106double TOI::getError(int i) {
107 if (errorTOI == NULL) throw NotFoundExc("TOI::getDataError : no Error TOI");
108 return errorTOI->getData(i);
109}
110
111void 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
119double TOI::getData(int i) { /* deprecated, overriden in toisegment */
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
129void TOI::getData(int i, double &data, uint_8 &flag) { /* deprecated, overriden in toisegment */
130 lock();
131 doGetData(i, data, flag);
132 unlock();
133 if (fgsigput) { fgsigput = false; broadcast(); }
134 return;
135}
136
137void TOI::getData(int i, int n, double* data, uint_8* flg) {
138 cerr << "TOI::getData [double*] unimplemented" << endl;
139 exit(-1);
140}
141
142void TOI::putData(int i, int n, double const* var, uint_8 const* flg) {
143 cerr << "TOI::putData [double*] unimplemented" << endl;
144 exit(-1);
145}
146
147void TOI::putData(int i, double value, uint_8 flag) { /* deprecated, overriden in toisegment */
148 lock();
149 doPutData(i, value, flag);
150 unlock();
151 if (fgsigget) { fgsigget = false; broadcast(); }
152}
153
154void TOI::waitForData(int iStart, int iEnd) { /* deprecated, overriden in toisegment */
155 if (producer == NULL) throw NotFoundExc("TOI has no producer !");
156
157 DataStatus s = isDataAvail(iStart, iEnd);
158 if (s == DATA_OK) {
159 return;
160 }
161 if (s == DATA_DELETED) {
162 throw NotFoundExc("Data has been purged !");
163 }
164
165 producer->lock();
166 while (isDataAvailNL(iStart, iEnd) == DATA_NOT_YET) {
167 producer->wait();
168 }
169 producer->unlock();
170 return;
171}
172
173void TOI::waitForData(int i) { /* deprecated, overriden in toisegment */
174 waitForData(i,i);
175}
176
177void TOI::waitForAnyData() { /* deprecated, overriden in toisegment */
178 if (! hasSomeData()) {
179 producer->lock();
180 producer->wait();
181 producer->unlock();
182 }
183}
184
185TOI::DataStatus TOI::isDataAvail(int i) {
186 lock();
187 DataStatus stat = isDataAvailNL(i);
188 unlock();
189 return stat;
190}
191
192TOI::DataStatus TOI::isDataAvail(int i, int j) {
193 lock();
194 DataStatus stat = isDataAvailNL(i,j);
195 unlock();
196 return stat;
197}
198
199TOI::DataStatus TOI::isDataAvailNL(int i) {
200 return isDataAvailNL(i,i);
201}
202
203void TOI::wontNeedBefore(int i) { /* deprecated, overriden in toisegment */
204 int j=i;
205 for (vector<TOIProcessor*>::iterator k = consumers.begin();
206 k != consumers.end(); k++) {
207 if ((*k)->wontNeedValue < j) j = (*k)->wontNeedValue;
208 }
209 lock();
210 doWontNeedBefore(j);
211 unlock();
212}
213
214void TOI::doWontNeedBefore(int i) {
215}
216
217
Note: See TracBrowser for help on using the repository browser.