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

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

une optim pour quand on n'a que des segmented

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.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
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) {
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) {
130 lock();
131 doGetData(i, data, flag);
132 unlock();
133 if (fgsigput) { fgsigput = false; broadcast(); }
134 return;
135}
136
137
138
139void 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
146void 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
165void TOI::waitForData(int i) {
166 waitForData(i,i);
167}
168
169void TOI::waitForAnyData() {
170 if (! hasSomeData()) {
171 producer->lock();
172 producer->wait();
173 producer->unlock();
174 }
175}
176
177TOI::DataStatus TOI::isDataAvail(int i) {
178 lock();
179 DataStatus stat = isDataAvailNL(i);
180 unlock();
181 return stat;
182}
183
184TOI::DataStatus TOI::isDataAvail(int i, int j) {
185 lock();
186 DataStatus stat = isDataAvailNL(i,j);
187 unlock();
188 return stat;
189}
190
191TOI::DataStatus TOI::isDataAvailNL(int i) {
192 return isDataAvailNL(i,i);
193}
194
195void 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
206void TOI::doWontNeedBefore(int i) {
207}
208
209
Note: See TracBrowser for help on using the repository browser.