diff --git a/src/backend/ready_queue.cc b/src/backend/ready_queue.cc index 80a2375..46d515b 100644 --- a/src/backend/ready_queue.cc +++ b/src/backend/ready_queue.cc @@ -70,3 +70,9 @@ ReadyQueue::append(Thread& thread) { _scheds.push_back(&thread); } + +void +ReadyQueue::erase_first() +{ + _scheds.erase(_scheds.begin()); +} \ No newline at end of file diff --git a/src/backend/ready_queue.hh b/src/backend/ready_queue.hh index eef3232..b232a79 100644 --- a/src/backend/ready_queue.hh +++ b/src/backend/ready_queue.hh @@ -42,6 +42,7 @@ namespace sgpem Thread& get_item_at(position index) throw (std::out_of_range); const Thread& get_item_at(position index) const throw (std::out_of_range); void append(Thread& schedulable); + void erase_first(); private: typedef std::vector Threads; diff --git a/src/backend/scheduler.cc b/src/backend/scheduler.cc index 5094a09..909ae3e 100644 --- a/src/backend/scheduler.cc +++ b/src/backend/scheduler.cc @@ -314,6 +314,10 @@ Scheduler::step_forward(History& history, CPUPolicy& cpu_policy) throw(UserInter DynamicThread& new_running = (DynamicThread&) _ready_queue->get_item_at(0); new_running.set_state(Schedulable::state_running); new_running.set_last_acquisition(current_instant); + // removes running element from the ready queue + // since no method was provided to erase an item in the queue, we should rebuild it. + // this is pointless. I just added the method. + _ready_queue->erase_first(); } diff --git a/src/text_simulation.cc b/src/text_simulation.cc index aa1e495..d6d71f9 100644 --- a/src/text_simulation.cc +++ b/src/text_simulation.cc @@ -1417,8 +1417,16 @@ TextSimulation::update(const History& changed_history) { ostringstream oss; - oss << ">>>> " << changed_history.get_size() - 1 << _("\nREADY QUEUE: { "); - + /// since the history stores snapshots starting from + /// and including instant -1, the first snapshot on + /// the queue, i.e. changed_history[0] is actually + /// the snapshot corresponding to instant -1. + /// therefore, the last snapshot on the history refers + /// to instant (history.get_size() - 2). + // this is a damn uint, so we must hack and hack + int printed_instant = changed_history.get_size() > 1 ? changed_history.get_size() - 2 : -1; + oss << ">>>> " << printed_instant << _("\nREADY QUEUE: { "); + p_stdout(oss.str()); oss.str(string());