- Added full request support, altough still not working
at all. Compiles and runs, but the output is not correct. Anyway, now it is just a matter of logics :P - Corrected some minor bugs in step forward. - Step forward is now rather messy, but still better than four hours ago.. altough this can be hard to believe. - Added some wizards that help finding bugs. - Rewritten dyn process get_state as it was guilty of premature optimization :) git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@825 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
efe7dedd61
commit
574723a35b
6 changed files with 658 additions and 363 deletions
|
@ -71,6 +71,63 @@ DynamicProcess::get_threads() const
|
|||
Schedulable::state
|
||||
DynamicProcess::get_state() const
|
||||
{
|
||||
int total = _dynamic_threads.size();
|
||||
int running = 0;
|
||||
int ready = 0;
|
||||
int blocked = 0;
|
||||
int terminated = 0;
|
||||
int future = 0;
|
||||
|
||||
unsigned int closest = 0;
|
||||
|
||||
vector<DynamicThread*>::const_iterator it = _dynamic_threads.begin();
|
||||
for(; it != _dynamic_threads.end(); it++)
|
||||
{
|
||||
if ((**it).get_state() == state_running) running++;
|
||||
if ((**it).get_state() == state_ready) ready++;
|
||||
if ((**it).get_state() == state_blocked) blocked++;
|
||||
if ((**it).get_state() == state_terminated) terminated++;
|
||||
if ((**it).get_state() == state_future)
|
||||
{
|
||||
unsigned int arrival = (**it).get_arrival_time();
|
||||
// if this is the first future occurrence, record its arrival;
|
||||
// else record its arrival if and only if it is smaller then the recorded one
|
||||
if (future == 0)
|
||||
closest = arrival;
|
||||
else
|
||||
closest = (closest < arrival) ? closest : arrival;
|
||||
future++;
|
||||
}
|
||||
}
|
||||
|
||||
assert(total > 0);
|
||||
assert(running == 1 || running == 0);
|
||||
assert(running + ready + blocked + terminated + future == total);
|
||||
|
||||
if (running > 0)
|
||||
return state_running;
|
||||
if (ready > 0) // running == 0
|
||||
return state_ready;
|
||||
if (blocked > 0) // running == 0 && ready == 0
|
||||
return state_blocked;
|
||||
// Now check if a "hole" happens: if all threads are terminated
|
||||
// or blocked the next
|
||||
// thread to start, e.g. the one with the least arrival_time, has
|
||||
// start time greater than the current process elapsed time, then
|
||||
// pass from state_future to state_terminated:
|
||||
if (closest > get_elapsed_time())
|
||||
return state_terminated;
|
||||
if (terminated > 0) // running == 0 && ready == 0 && blocked == 0
|
||||
return state_terminated;
|
||||
if (future > 0) // running == 0 && ready == 0 && blocked == 0 && terminated == 0
|
||||
return state_future;
|
||||
|
||||
// Since premature optimization is the root of all evil, and the
|
||||
// following code was very fast but also very wrong, the coder
|
||||
// will be punished by allowing her to code in C++ just after
|
||||
// having passed "Algoritmi 3" exam with full marks.
|
||||
|
||||
/*
|
||||
typedef vector<DynamicThread*>::const_iterator ThreadIt;
|
||||
static const int uninitialized = -1;
|
||||
|
||||
|
@ -103,6 +160,7 @@ DynamicProcess::get_state() const
|
|||
|
||||
// TODO Is this OK? Must be tested...
|
||||
|
||||
|
||||
int thread_starts_at;
|
||||
switch(thread_state)
|
||||
{
|
||||
|
@ -125,20 +183,10 @@ DynamicProcess::get_state() const
|
|||
default: // (e)
|
||||
result = state_terminated;
|
||||
}
|
||||
|
||||
} //~ "for" iterating over threads
|
||||
|
||||
// Now check if a "hole" happens: if result == state_future, but the next
|
||||
// thread to start, e.g. the one with the least arrival_time, has
|
||||
// start time greater than the current process elapsed time, then
|
||||
// pass from state_future to state_terminated:
|
||||
|
||||
// (d2)
|
||||
int elapsed_time = get_elapsed_time();
|
||||
if(result == state_future && next_thread_starts_at > elapsed_time )
|
||||
result = state_terminated;
|
||||
|
||||
return result;
|
||||
// reused hole checking system
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue