[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 | |
---|
| 42 | void ProcessingQueue::mark_ready(Address &element) |
---|
| 43 | { |
---|
| 44 | /* |
---|
| 45 | list<ProcessingElement>::iterator it; |
---|
| 46 | for (it=elements.begin(); it!= elements.end(); it++) { |
---|
| 47 | ProcessingElement el = *it; |
---|
| 48 | if (el.address == element) { |
---|
| 49 | if (el.processing_type == EXTERNAL_WAIT) { |
---|
| 50 | el.is_ready = true; |
---|
| 51 | } else { |
---|
| 52 | //cout << "marking duplicate or incorrect element as ready" << endl; |
---|
| 53 | } |
---|
| 54 | } |
---|
| 55 | }*/ |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | Address* ProcessingQueue::get_next_ready() |
---|
| 59 | { |
---|
| 60 | |
---|
| 61 | //cout << "appel a get_next_ready" << endl; |
---|
| 62 | list<ProcessingElement>::iterator it; |
---|
| 63 | for (it=elements.begin(); it!= elements.end(); it++) { |
---|
| 64 | if (it->processing_type == EXTERNAL_WAIT) { |
---|
| 65 | if (it->is_ready == true) { |
---|
| 66 | //cout << "suppression de l'element : " << el; |
---|
| 67 | elements.erase(it); |
---|
| 68 | return &(it->address); |
---|
| 69 | } else { |
---|
| 70 | //cout << "get_next_ready incorrect behavior" << endl; |
---|
| 71 | exit (5439405); |
---|
| 72 | } |
---|
| 73 | } else { |
---|
| 74 | //cout << "l'element est en internal timeout" << endl; |
---|
| 75 | if (it->latency == 0){ |
---|
| 76 | //cout << "suppression de l'element" << *it << endl; |
---|
| 77 | elements.erase(it); |
---|
| 78 | return &(it->address); |
---|
| 79 | } |
---|
| 80 | } |
---|
| 81 | } |
---|
| 82 | //cout << "retour de get_next_ready : null" << endl; |
---|
| 83 | |
---|
| 84 | return NULL; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | /* |
---|
| 88 | int ProcessingQueue::get_ready_element() { |
---|
| 89 | list<ProcessingElement>::iterator it; |
---|
| 90 | it = elements.begin(); |
---|
| 91 | ProcessingElement el = *it; |
---|
| 92 | if (el.current_latency != timer) { |
---|
| 93 | //cout << "please use has_ready_element before. Aborting" << endl; |
---|
| 94 | exit (-123213); |
---|
| 95 | } else { |
---|
| 96 | elements.pop_front(); |
---|
| 97 | return el.address; |
---|
| 98 | } |
---|
| 99 | } |
---|
| 100 | */ |
---|
| 101 | /* |
---|
| 102 | bool ProcessingQueue::has_ready_element() |
---|
| 103 | { |
---|
| 104 | list<ProcessingElement>::iterator it; |
---|
| 105 | it = elements.begin(); |
---|
| 106 | if (elements.size() == 0) |
---|
| 107 | return false; |
---|
| 108 | |
---|
| 109 | ProcessingElement el = *it; |
---|
| 110 | if (el.current_latency == timer) { |
---|
| 111 | return true; |
---|
| 112 | } else { |
---|
| 113 | return false; |
---|
| 114 | } |
---|
| 115 | } |
---|
| 116 | */ |
---|
| 117 | void ProcessingQueue::print() |
---|
| 118 | { |
---|
| 119 | cout << "\t" << "Processing QUEUE START" << endl; |
---|
| 120 | |
---|
| 121 | for(list<ProcessingElement>::iterator it=elements.begin(); it!=elements.end(); it++) |
---|
| 122 | { |
---|
| 123 | cout << "\t\t" << "element : " << *it << endl; |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | cout << "\t" << "Processing QUEUE STOP" << endl; |
---|
| 127 | } |
---|