[1738] | 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 |
|
---|
[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;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | TOI::~TOI() {
|
---|
| 42 | pthread_mutex_destroy(&mutex);
|
---|
| 43 | }
|
---|
| 44 |
|
---|
[1437] | 45 | void 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 |
|
---|
[1365] | 59 | void TOI::setProducer(TOIProcessor* p) {
|
---|
| 60 | if (producer)
|
---|
| 61 | throw DuplicateIdExc("TOI::setProducer : producer already defined");
|
---|
| 62 | producer = p;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | void TOI::addConsumer(TOIProcessor* p) {
|
---|
| 66 | consumers.push_back(p);
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | int TOI::getMinSn(){
|
---|
| 70 | return producer->getMinOut();
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | int TOI::getMaxSn(){
|
---|
| 74 | return producer->getMaxOut();
|
---|
| 75 | }
|
---|
| 76 |
|
---|
[1464] | 77 | /*
|
---|
| 78 | RZCMV ----- l'interface va etre modifiee, NE PAS UTILISER
|
---|
| 79 | #ifndef NO_SOPHYA
|
---|
[1365] | 80 | Array TOI::getError(int iStart, int iEnd) {
|
---|
| 81 | if (errorTOI == NULL) throw NotFoundExc("TOI::getDataError : no Error TOI");
|
---|
[1464] | 82 | return errorTOI->getData(iStart, iEnd);
|
---|
[1365] | 83 | }
|
---|
[1464] | 84 | Array 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 | }
|
---|
| 91 | TArray<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 | }
|
---|
[1365] | 98 | #endif
|
---|
[1464] | 99 | l'interface va etre modifiee, NE PAS UTILISER ----
|
---|
| 100 | */
|
---|
[1365] | 101 |
|
---|
[1464] | 102 |
|
---|
| 103 | /*
|
---|
| 104 | RZCMV ------- A revoir les getError() ...
|
---|
[1365] | 105 | double TOI::getError(int i) {
|
---|
| 106 | if (errorTOI == NULL) throw NotFoundExc("TOI::getDataError : no Error TOI");
|
---|
| 107 | return errorTOI->getData(i);
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | void 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 |
|
---|
[1462] | 116 | */
|
---|
| 117 |
|
---|
[1365] | 118 | double TOI::getData(int i) {
|
---|
| 119 | lock();
|
---|
[1532] | 120 | uint_8 flg;
|
---|
[1462] | 121 | double dat;
|
---|
| 122 | doGetData(i, dat, flg);
|
---|
[1365] | 123 | unlock();
|
---|
[1437] | 124 | if (fgsigput) { fgsigput = false; broadcast(); }
|
---|
[1365] | 125 | return dat;
|
---|
| 126 | }
|
---|
| 127 |
|
---|
[1532] | 128 | void TOI::getData(int i, double &data, uint_8 &flag) {
|
---|
[1462] | 129 | lock();
|
---|
| 130 | doGetData(i, data, flag);
|
---|
| 131 | unlock();
|
---|
| 132 | if (fgsigput) { fgsigput = false; broadcast(); }
|
---|
| 133 | return;
|
---|
| 134 | }
|
---|
[1365] | 135 |
|
---|
| 136 |
|
---|
| 137 |
|
---|
[1532] | 138 | void TOI::putData(int i, double value, uint_8 flag) {
|
---|
[1365] | 139 | lock();
|
---|
| 140 | doPutData(i, value, flag);
|
---|
| 141 | unlock();
|
---|
[1437] | 142 | if (fgsigget) { fgsigget = false; broadcast(); }
|
---|
[1365] | 143 | }
|
---|
| 144 |
|
---|
| 145 | void 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 |
|
---|
| 164 | void TOI::waitForData(int i) {
|
---|
| 165 | waitForData(i,i);
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | void TOI::waitForAnyData() {
|
---|
| 169 | if (! hasSomeData()) {
|
---|
| 170 | producer->lock();
|
---|
| 171 | producer->wait();
|
---|
| 172 | producer->unlock();
|
---|
| 173 | }
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | TOI::DataStatus TOI::isDataAvail(int i) {
|
---|
| 177 | lock();
|
---|
| 178 | DataStatus stat = isDataAvailNL(i);
|
---|
| 179 | unlock();
|
---|
| 180 | return stat;
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | TOI::DataStatus TOI::isDataAvail(int i, int j) {
|
---|
| 184 | lock();
|
---|
| 185 | DataStatus stat = isDataAvailNL(i,j);
|
---|
| 186 | unlock();
|
---|
| 187 | return stat;
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 | TOI::DataStatus TOI::isDataAvailNL(int i) {
|
---|
| 191 | return isDataAvailNL(i,i);
|
---|
| 192 | }
|
---|
| 193 |
|
---|
| 194 | void 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 |
|
---|
| 205 | void TOI::doWontNeedBefore(int i) {
|
---|
| 206 | }
|
---|
| 207 |
|
---|
| 208 |
|
---|