[1365] | 1 | #include "toiprocessor.h"
|
---|
| 2 | #include "toi.h"
|
---|
| 3 | #include <pthread.h>
|
---|
| 4 |
|
---|
| 5 | #ifdef WITH_SOPHYA
|
---|
| 6 | #include "pexceptions.h"
|
---|
| 7 | #else
|
---|
| 8 | #include "apexceptions.h"
|
---|
| 9 | #endif
|
---|
| 10 |
|
---|
| 11 |
|
---|
| 12 | TOI::TOI() {
|
---|
| 13 | TOIInit();
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 | TOI::TOI(string n) {
|
---|
| 17 | name = n;
|
---|
| 18 | TOIInit();
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | void TOI::TOIInit() {
|
---|
| 22 | pthread_mutex_init(&mutex, NULL);
|
---|
[1437] | 23 | // ----- Rajouts Reza 12/3/2001
|
---|
| 24 | pthread_cond_init(&condv, NULL);
|
---|
| 25 | fgwaitput = fgwaitget = false;
|
---|
| 26 | fgsigput = fgsigget = false;
|
---|
| 27 | countwaitput = countwaitget = 0;
|
---|
| 28 | // Fin rajouts Reza 12/3/2001 ------
|
---|
[1365] | 29 | // pthread_mutex_setname_np(&mutex, (name + "_toi_mutex").c_str(), 0);
|
---|
| 30 | defaultValue = 0;
|
---|
| 31 | producer = NULL;
|
---|
| 32 | dbg = false;
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | TOI::~TOI() {
|
---|
| 36 | pthread_mutex_destroy(&mutex);
|
---|
| 37 | }
|
---|
| 38 |
|
---|
[1437] | 39 | void TOI::PrintStatus(ostream & os) const
|
---|
| 40 | {
|
---|
| 41 | os << "TOI::PrintStatus() - Name=" << getName() << endl;
|
---|
| 42 | os << " WaitStatus: Put/" ;
|
---|
| 43 | if (isPutWaiting()) os << "Waiting " ;
|
---|
| 44 | else os << "Running ";
|
---|
| 45 | os << " PutCountWait= " << getCountWaitPut() << endl;
|
---|
| 46 | os << " WaitStatus: Get/" ;
|
---|
| 47 | if (isGetWaiting()) os << "Waiting " ;
|
---|
| 48 | else os << "Running ";
|
---|
| 49 | os << " GetCountWait= " << getCountWaitGet() << endl;
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 |
|
---|
[1365] | 53 | void TOI::setProducer(TOIProcessor* p) {
|
---|
| 54 | if (producer)
|
---|
| 55 | throw DuplicateIdExc("TOI::setProducer : producer already defined");
|
---|
| 56 | producer = p;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | void TOI::addConsumer(TOIProcessor* p) {
|
---|
| 60 | consumers.push_back(p);
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | int TOI::getMinSn(){
|
---|
| 64 | return producer->getMinOut();
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | int TOI::getMaxSn(){
|
---|
| 68 | return producer->getMaxOut();
|
---|
| 69 | }
|
---|
| 70 |
|
---|
[1464] | 71 | /*
|
---|
| 72 | RZCMV ----- l'interface va etre modifiee, NE PAS UTILISER
|
---|
| 73 | #ifndef NO_SOPHYA
|
---|
[1365] | 74 | Array TOI::getError(int iStart, int iEnd) {
|
---|
| 75 | if (errorTOI == NULL) throw NotFoundExc("TOI::getDataError : no Error TOI");
|
---|
[1464] | 76 | return errorTOI->getData(iStart, iEnd);
|
---|
[1365] | 77 | }
|
---|
[1464] | 78 | Array TOI::getData(int iStart, int iEnd) {
|
---|
| 79 | lock();
|
---|
| 80 | Array a = doGetData(iStart, iEnd);
|
---|
| 81 | unlock();
|
---|
| 82 | if (fgsigput) { fgsigput = false; broadcast(); }
|
---|
| 83 | return a;
|
---|
| 84 | }
|
---|
| 85 | TArray<int_4> TOI::getFlag(int iStart, int iEnd) {
|
---|
| 86 | lock();
|
---|
| 87 | TArray<int_4> a = doGetFlag(iStart, iEnd);
|
---|
| 88 | unlock();
|
---|
| 89 | if (fgsigput) { fgsigput = false; broadcast(); }
|
---|
| 90 | return a;
|
---|
| 91 | }
|
---|
[1365] | 92 | #endif
|
---|
[1464] | 93 | l'interface va etre modifiee, NE PAS UTILISER ----
|
---|
| 94 | */
|
---|
[1365] | 95 |
|
---|
[1464] | 96 |
|
---|
| 97 | /*
|
---|
| 98 | RZCMV ------- A revoir les getError() ...
|
---|
[1365] | 99 | double TOI::getError(int i) {
|
---|
| 100 | if (errorTOI == NULL) throw NotFoundExc("TOI::getDataError : no Error TOI");
|
---|
| 101 | return errorTOI->getData(i);
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | void TOI::putDataError(int i, double value, double error, int_4 flag) {
|
---|
| 105 | if (errorTOI == NULL) throw NotFoundExc("TOI::getDataError : no Error TOI");
|
---|
| 106 | putData(i, value, flag);
|
---|
| 107 | errorTOI->putData(i, value, flag);
|
---|
| 108 | }
|
---|
| 109 |
|
---|
[1462] | 110 | */
|
---|
| 111 |
|
---|
[1365] | 112 | double TOI::getData(int i) {
|
---|
| 113 | lock();
|
---|
[1532] | 114 | uint_8 flg;
|
---|
[1462] | 115 | double dat;
|
---|
| 116 | doGetData(i, dat, flg);
|
---|
[1365] | 117 | unlock();
|
---|
[1437] | 118 | if (fgsigput) { fgsigput = false; broadcast(); }
|
---|
[1365] | 119 | return dat;
|
---|
| 120 | }
|
---|
| 121 |
|
---|
[1532] | 122 | void TOI::getData(int i, double &data, uint_8 &flag) {
|
---|
[1462] | 123 | lock();
|
---|
| 124 | doGetData(i, data, flag);
|
---|
| 125 | unlock();
|
---|
| 126 | if (fgsigput) { fgsigput = false; broadcast(); }
|
---|
| 127 | return;
|
---|
| 128 | }
|
---|
[1365] | 129 |
|
---|
| 130 |
|
---|
| 131 |
|
---|
[1532] | 132 | void TOI::putData(int i, double value, uint_8 flag) {
|
---|
[1365] | 133 | lock();
|
---|
| 134 | doPutData(i, value, flag);
|
---|
| 135 | unlock();
|
---|
[1437] | 136 | if (fgsigget) { fgsigget = false; broadcast(); }
|
---|
[1365] | 137 | }
|
---|
| 138 |
|
---|
| 139 | void TOI::waitForData(int iStart, int iEnd) {
|
---|
| 140 | if (producer == NULL) throw NotFoundExc("TOI has no producer !");
|
---|
| 141 |
|
---|
| 142 | DataStatus s = isDataAvail(iStart, iEnd);
|
---|
| 143 | if (s == DATA_OK) {
|
---|
| 144 | return;
|
---|
| 145 | }
|
---|
| 146 | if (s == DATA_DELETED) {
|
---|
| 147 | throw NotFoundExc("Data has been purged !");
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | producer->lock();
|
---|
| 151 | while (isDataAvailNL(iStart, iEnd) == DATA_NOT_YET) {
|
---|
| 152 | producer->wait();
|
---|
| 153 | }
|
---|
| 154 | producer->unlock();
|
---|
| 155 | return;
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | void TOI::waitForData(int i) {
|
---|
| 159 | waitForData(i,i);
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | void TOI::waitForAnyData() {
|
---|
| 163 | if (! hasSomeData()) {
|
---|
| 164 | producer->lock();
|
---|
| 165 | producer->wait();
|
---|
| 166 | producer->unlock();
|
---|
| 167 | }
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | TOI::DataStatus TOI::isDataAvail(int i) {
|
---|
| 171 | lock();
|
---|
| 172 | DataStatus stat = isDataAvailNL(i);
|
---|
| 173 | unlock();
|
---|
| 174 | return stat;
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | TOI::DataStatus TOI::isDataAvail(int i, int j) {
|
---|
| 178 | lock();
|
---|
| 179 | DataStatus stat = isDataAvailNL(i,j);
|
---|
| 180 | unlock();
|
---|
| 181 | return stat;
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | TOI::DataStatus TOI::isDataAvailNL(int i) {
|
---|
| 185 | return isDataAvailNL(i,i);
|
---|
| 186 | }
|
---|
| 187 |
|
---|
| 188 | void TOI::wontNeedBefore(int i) {
|
---|
| 189 | int j=i;
|
---|
| 190 | for (vector<TOIProcessor*>::iterator k = consumers.begin();
|
---|
| 191 | k != consumers.end(); k++) {
|
---|
| 192 | if ((*k)->wontNeedValue < j) j = (*k)->wontNeedValue;
|
---|
| 193 | }
|
---|
| 194 | lock();
|
---|
| 195 | doWontNeedBefore(j);
|
---|
| 196 | unlock();
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 | void TOI::doWontNeedBefore(int i) {
|
---|
| 200 | }
|
---|
| 201 |
|
---|
| 202 |
|
---|