[2] | 1 | #include "processing_queue.h" |
---|
| 2 | |
---|
| 3 | void ProcessingQueue::insert(const Address addr, unsigned int latency) |
---|
| 4 | { |
---|
| 5 | ProcessingElement el = |
---|
| 6 | { |
---|
| 7 | addr, |
---|
| 8 | INTERNAL_TIMEOUT, |
---|
| 9 | false, |
---|
| 10 | latency |
---|
| 11 | }; |
---|
| 12 | elements.push_back(el); |
---|
| 13 | } |
---|
| 14 | |
---|
| 15 | void ProcessingQueue::insert(const Address addr) |
---|
| 16 | { |
---|
| 17 | ProcessingElement el = |
---|
| 18 | { |
---|
| 19 | addr, |
---|
| 20 | EXTERNAL_WAIT, |
---|
| 21 | false, |
---|
| 22 | 0 |
---|
| 23 | }; |
---|
| 24 | elements.push_back(el); |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | void ProcessingQueue::update_time() |
---|
| 28 | { |
---|
| 29 | list<ProcessingElement>::iterator it; |
---|
| 30 | for (it = elements.begin(); it != elements.end(); it++) { |
---|
| 31 | if (it->processing_type == INTERNAL_TIMEOUT) { |
---|
| 32 | if (it->latency > 0){ |
---|
| 33 | it->latency--; |
---|
| 34 | } else { |
---|
| 35 | // FIXME readd this test |
---|
| 36 | // cout << "latency going under 0" << endl; |
---|
| 37 | } |
---|
| 38 | } |
---|
| 39 | } |
---|
| 40 | } |
---|
| 41 | |
---|
[16] | 42 | bool ProcessingQueue::is_empty() |
---|
| 43 | { |
---|
| 44 | return elements.empty(); |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | |
---|
[2] | 48 | void ProcessingQueue::mark_ready(Address &element) |
---|
| 49 | { |
---|
| 50 | /* |
---|
| 51 | list<ProcessingElement>::iterator it; |
---|
| 52 | for (it=elements.begin(); it!= elements.end(); it++) { |
---|
| 53 | ProcessingElement el = *it; |
---|
| 54 | if (el.address == element) { |
---|
| 55 | if (el.processing_type == EXTERNAL_WAIT) { |
---|
| 56 | el.is_ready = true; |
---|
| 57 | } else { |
---|
| 58 | //cout << "marking duplicate or incorrect element as ready" << endl; |
---|
| 59 | } |
---|
| 60 | } |
---|
| 61 | }*/ |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | Address* ProcessingQueue::get_next_ready() |
---|
| 65 | { |
---|
| 66 | |
---|
| 67 | //cout << "appel a get_next_ready" << endl; |
---|
| 68 | list<ProcessingElement>::iterator it; |
---|
| 69 | for (it=elements.begin(); it!= elements.end(); it++) { |
---|
| 70 | if (it->processing_type == EXTERNAL_WAIT) { |
---|
| 71 | if (it->is_ready == true) { |
---|
| 72 | //cout << "suppression de l'element : " << el; |
---|
| 73 | elements.erase(it); |
---|
| 74 | return &(it->address); |
---|
| 75 | } else { |
---|
| 76 | //cout << "get_next_ready incorrect behavior" << endl; |
---|
| 77 | exit (5439405); |
---|
| 78 | } |
---|
| 79 | } else { |
---|
| 80 | //cout << "l'element est en internal timeout" << endl; |
---|
| 81 | if (it->latency == 0){ |
---|
| 82 | //cout << "suppression de l'element" << *it << endl; |
---|
| 83 | elements.erase(it); |
---|
| 84 | return &(it->address); |
---|
| 85 | } |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | //cout << "retour de get_next_ready : null" << endl; |
---|
| 89 | |
---|
| 90 | return NULL; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | /* |
---|
| 94 | int ProcessingQueue::get_ready_element() { |
---|
| 95 | list<ProcessingElement>::iterator it; |
---|
| 96 | it = elements.begin(); |
---|
| 97 | ProcessingElement el = *it; |
---|
| 98 | if (el.current_latency != timer) { |
---|
| 99 | //cout << "please use has_ready_element before. Aborting" << endl; |
---|
| 100 | exit (-123213); |
---|
| 101 | } else { |
---|
| 102 | elements.pop_front(); |
---|
| 103 | return el.address; |
---|
| 104 | } |
---|
| 105 | } |
---|
| 106 | */ |
---|
| 107 | /* |
---|
| 108 | bool ProcessingQueue::has_ready_element() |
---|
| 109 | { |
---|
| 110 | list<ProcessingElement>::iterator it; |
---|
| 111 | it = elements.begin(); |
---|
| 112 | if (elements.size() == 0) |
---|
| 113 | return false; |
---|
| 114 | |
---|
| 115 | ProcessingElement el = *it; |
---|
| 116 | if (el.current_latency == timer) { |
---|
| 117 | return true; |
---|
| 118 | } else { |
---|
| 119 | return false; |
---|
| 120 | } |
---|
| 121 | } |
---|
| 122 | */ |
---|
| 123 | void ProcessingQueue::print() |
---|
| 124 | { |
---|
| 125 | cout << "\t" << "Processing QUEUE START" << endl; |
---|
| 126 | |
---|
| 127 | for(list<ProcessingElement>::iterator it=elements.begin(); it!=elements.end(); it++) |
---|
| 128 | { |
---|
| 129 | cout << "\t\t" << "element : " << *it << endl; |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | cout << "\t" << "Processing QUEUE STOP" << endl; |
---|
| 133 | } |
---|