[1738] | 1 | // ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
|
---|
| 2 | // Eric Aubourg
|
---|
| 3 | // Christophe Magneville
|
---|
| 4 | // Reza Ansari
|
---|
[1740] | 5 | // $Id: toi.cc,v 1.8 2001-11-08 23:23:58 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 |
|
---|
[1437] | 46 | void 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 |
|
---|
[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 |
|
---|
[1365] | 119 | double TOI::getData(int i) {
|
---|
| 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 |
|
---|
[1532] | 129 | void TOI::getData(int i, double &data, uint_8 &flag) {
|
---|
[1462] | 130 | lock();
|
---|
| 131 | doGetData(i, data, flag);
|
---|
| 132 | unlock();
|
---|
| 133 | if (fgsigput) { fgsigput = false; broadcast(); }
|
---|
| 134 | return;
|
---|
| 135 | }
|
---|
[1365] | 136 |
|
---|
| 137 |
|
---|
| 138 |
|
---|
[1532] | 139 | void TOI::putData(int i, double value, uint_8 flag) {
|
---|
[1365] | 140 | lock();
|
---|
| 141 | doPutData(i, value, flag);
|
---|
| 142 | unlock();
|
---|
[1437] | 143 | if (fgsigget) { fgsigget = false; broadcast(); }
|
---|
[1365] | 144 | }
|
---|
| 145 |
|
---|
| 146 | void 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 |
|
---|
| 165 | void TOI::waitForData(int i) {
|
---|
| 166 | waitForData(i,i);
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 | void TOI::waitForAnyData() {
|
---|
| 170 | if (! hasSomeData()) {
|
---|
| 171 | producer->lock();
|
---|
| 172 | producer->wait();
|
---|
| 173 | producer->unlock();
|
---|
| 174 | }
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | TOI::DataStatus TOI::isDataAvail(int i) {
|
---|
| 178 | lock();
|
---|
| 179 | DataStatus stat = isDataAvailNL(i);
|
---|
| 180 | unlock();
|
---|
| 181 | return stat;
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | TOI::DataStatus TOI::isDataAvail(int i, int j) {
|
---|
| 185 | lock();
|
---|
| 186 | DataStatus stat = isDataAvailNL(i,j);
|
---|
| 187 | unlock();
|
---|
| 188 | return stat;
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 | TOI::DataStatus TOI::isDataAvailNL(int i) {
|
---|
| 192 | return isDataAvailNL(i,i);
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | void 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 |
|
---|
| 206 | void TOI::doWontNeedBefore(int i) {
|
---|
| 207 | }
|
---|
| 208 |
|
---|
| 209 |
|
---|