[1738] | 1 | // ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
|
---|
| 2 | // Eric Aubourg
|
---|
| 3 | // Christophe Magneville
|
---|
| 4 | // Reza Ansari
|
---|
[1762] | 5 | // $Id: toi.cc,v 1.11 2001-11-13 16:22:47 aubourg Exp $
|
---|
[1738] | 6 |
|
---|
[1365] | 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);
|
---|
[1437] | 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 ------
|
---|
[1365] | 35 | // pthread_mutex_setname_np(&mutex, (name + "_toi_mutex").c_str(), 0);
|
---|
| 36 | defaultValue = 0;
|
---|
| 37 | producer = NULL;
|
---|
| 38 | dbg = false;
|
---|
[1740] | 39 | syncOldWay = true;
|
---|
[1365] | 40 | }
|
---|
| 41 |
|
---|
| 42 | TOI::~TOI() {
|
---|
| 43 | pthread_mutex_destroy(&mutex);
|
---|
| 44 | }
|
---|
| 45 |
|
---|
[1762] | 46 | void TOI::PrintStatus(::ostream & os) const
|
---|
[1437] | 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 |
|
---|
[1365] | 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 |
|
---|
[1464] | 78 | /*
|
---|
| 79 | RZCMV ----- l'interface va etre modifiee, NE PAS UTILISER
|
---|
| 80 | #ifndef NO_SOPHYA
|
---|
[1365] | 81 | Array TOI::getError(int iStart, int iEnd) {
|
---|
| 82 | if (errorTOI == NULL) throw NotFoundExc("TOI::getDataError : no Error TOI");
|
---|
[1464] | 83 | return errorTOI->getData(iStart, iEnd);
|
---|
[1365] | 84 | }
|
---|
[1464] | 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 | }
|
---|
[1365] | 99 | #endif
|
---|
[1464] | 100 | l'interface va etre modifiee, NE PAS UTILISER ----
|
---|
| 101 | */
|
---|
[1365] | 102 |
|
---|
[1464] | 103 |
|
---|
| 104 | /*
|
---|
| 105 | RZCMV ------- A revoir les getError() ...
|
---|
[1365] | 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 |
|
---|
[1462] | 117 | */
|
---|
| 118 |
|
---|
[1742] | 119 | double TOI::getData(int i) { /* deprecated, overriden in toisegment */
|
---|
[1365] | 120 | lock();
|
---|
[1532] | 121 | uint_8 flg;
|
---|
[1462] | 122 | double dat;
|
---|
| 123 | doGetData(i, dat, flg);
|
---|
[1365] | 124 | unlock();
|
---|
[1437] | 125 | if (fgsigput) { fgsigput = false; broadcast(); }
|
---|
[1365] | 126 | return dat;
|
---|
| 127 | }
|
---|
| 128 |
|
---|
[1742] | 129 | void TOI::getData(int i, double &data, uint_8 &flag) { /* deprecated, overriden in toisegment */
|
---|
[1462] | 130 | lock();
|
---|
| 131 | doGetData(i, data, flag);
|
---|
| 132 | unlock();
|
---|
| 133 | if (fgsigput) { fgsigput = false; broadcast(); }
|
---|
| 134 | return;
|
---|
| 135 | }
|
---|
[1365] | 136 |
|
---|
[1742] | 137 | void TOI::getData(int i, int n, double* data, uint_8* flg) {
|
---|
| 138 | cerr << "TOI::getData [double*] unimplemented" << endl;
|
---|
| 139 | exit(-1);
|
---|
| 140 | }
|
---|
[1365] | 141 |
|
---|
[1742] | 142 | void 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 |
|
---|
| 147 | void TOI::putData(int i, double value, uint_8 flag) { /* deprecated, overriden in toisegment */
|
---|
[1365] | 148 | lock();
|
---|
| 149 | doPutData(i, value, flag);
|
---|
| 150 | unlock();
|
---|
[1437] | 151 | if (fgsigget) { fgsigget = false; broadcast(); }
|
---|
[1365] | 152 | }
|
---|
| 153 |
|
---|
[1742] | 154 | void TOI::waitForData(int iStart, int iEnd) { /* deprecated, overriden in toisegment */
|
---|
[1365] | 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 |
|
---|
[1742] | 173 | void TOI::waitForData(int i) { /* deprecated, overriden in toisegment */
|
---|
[1365] | 174 | waitForData(i,i);
|
---|
| 175 | }
|
---|
| 176 |
|
---|
[1742] | 177 | void TOI::waitForAnyData() { /* deprecated, overriden in toisegment */
|
---|
[1365] | 178 | if (! hasSomeData()) {
|
---|
| 179 | producer->lock();
|
---|
| 180 | producer->wait();
|
---|
| 181 | producer->unlock();
|
---|
| 182 | }
|
---|
| 183 | }
|
---|
| 184 |
|
---|
| 185 | TOI::DataStatus TOI::isDataAvail(int i) {
|
---|
| 186 | lock();
|
---|
| 187 | DataStatus stat = isDataAvailNL(i);
|
---|
| 188 | unlock();
|
---|
| 189 | return stat;
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | TOI::DataStatus TOI::isDataAvail(int i, int j) {
|
---|
| 193 | lock();
|
---|
| 194 | DataStatus stat = isDataAvailNL(i,j);
|
---|
| 195 | unlock();
|
---|
| 196 | return stat;
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 | TOI::DataStatus TOI::isDataAvailNL(int i) {
|
---|
| 200 | return isDataAvailNL(i,i);
|
---|
| 201 | }
|
---|
| 202 |
|
---|
[1742] | 203 | void TOI::wontNeedBefore(int i) { /* deprecated, overriden in toisegment */
|
---|
[1365] | 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 |
|
---|
| 214 | void TOI::doWontNeedBefore(int i) {
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 |
|
---|