RINASim  October 2016
Documentation of framework for OMNeT++
IterativeScheduling.cc
Go to the documentation of this file.
1 //
2 // This program is free software: you can redistribute it and/or modify
3 // it under the terms of the GNU Lesser General Public License as published by
4 // the Free Software Foundation, either version 3 of the License, or
5 // (at your option) any later version.
6 //
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public License
13 // along with this program. If not, see http://www.gnu.org/licenses/.
14 //
15 
16 #include "IterativeScheduling.h"
17 
18 
19 namespace IterativeScheduling {
20 
22 
23 using namespace std;
24 
26  queues[port].insert(q);
27  if(queues[port].size() == 1) { lastQ[port] = queues[port].begin(); }
28  }
30  if(*lastQ[port] == q) { lastQ[port]++; }
31  queues[port].erase(q);
32  if(lastQ[port] == queues[port].end()) { lastQ[port] = queues[port].begin(); }
33  }
34 
36  Enter_Method("processQueues()");
37 
38  switch(direction){
39  case RMTQueue::INPUT:
40  if (port->isInputReady() && port->getWaiting(RMTQueue::INPUT)) {
42  inQ->releasePDU();
43  }
44  break;
45  case RMTQueue::OUTPUT:
46  if (port->isOutputReady() && port->getWaiting(RMTQueue::OUTPUT)) {
47  for( int k = queues[port].size(); k > 0; k--) {
48  RMTQueue * outQ = *lastQ[port];
49  if(outQ && outQ->getLength() > 0) {
50  lastQ[port]++;
51  if(lastQ[port] == queues[port].end()) { lastQ[port] = queues[port].begin(); }
52  outQ->releasePDU();
53  return;
54  } else {
55  lastQ[port]++;
56  if(lastQ[port] == queues[port].end()) { lastQ[port] = queues[port].begin(); }
57  }
58  }
59  }
60  }
61  }
62 
63 
65  if(par("printAtEnd").boolValue()) {
66  cout << "----------------" << endl;
67  std::cout << "IterativeScheduling::finish" << endl;
68  cout << getFullPath() << endl << endl;
69  for(auto & pl : queues) {
70  cout << pl.first->getFullPath() << endl;
71  for(auto & q : pl.second) {
72  cout << "\t" << q->getFullPath() << endl;
73  cout << "\t\t" << q->getLength();
74  cout << " / " << q->getThreshLength() << endl;
75  }
76  auto it = lastQ[pl.first];
77  if(it == pl.second.end()) {
78  cout << "\tCurrent : out of bounds" <<endl;
79  } else {
80  cout << "\tCurrent : " << (*it)->getFullPath() <<endl;
81  }
82  }
83  cout << "----------------" << endl;
84  }
85  }
86 
87 }
88 
void addQueue(RMTPort *port, RMTQueue *q)
RMTQueue * getLongestQueue(RMTQueueType type) const
Definition: RMTPort.cc:226
void releasePDU()
Definition: RMTQueue.cc:162
int getLength() const
Definition: RMTQueue.cc:210
unsigned long getWaiting(RMTQueueType direction)
Definition: RMTPort.cc:315
void removeQueue(RMTPort *port, RMTQueue *q)
bool isOutputReady()
Definition: RMTPort.cc:261
iterator begin()
Definition: RMTQueue.h:119
void processQueues(RMTPort *port, RMTQueueType direction)
bool isInputReady()
Definition: RMTPort.cc:282
Define_Module(IterativeMonitor)