- Pretty-indenting code

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@674 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-06-29 08:44:30 +00:00
parent 7aecc910ba
commit 6b27a8461b
94 changed files with 3073 additions and 3066 deletions

View file

@ -29,63 +29,63 @@ using namespace sgpem;
using std::vector;
DynamicProcess::DynamicProcess(StaticProcess* core) :
DynamicSchedulable(*core)
{
}
DynamicSchedulable(*core)
{}
DynamicProcess::DynamicProcess(const DynamicProcess &other) :
Schedulable(), DynamicSchedulable(other), Process()
Schedulable(), DynamicSchedulable(other), Process()
{
typedef vector<DynamicThread*>::const_iterator ThreadIt;
const vector<DynamicThread*>& other_threads = other._dynamic_threads;
for(ThreadIt it = other_threads.begin(); it != other_threads.end(); ++it)
_dynamic_threads.push_back(new DynamicThread(*(*it)));
}
std::vector<Thread*>
std::vector<Thread*>
DynamicProcess::get_threads()
{
return vector<Thread*>(_dynamic_threads.begin(), _dynamic_threads.end());
}
Schedulable::state
Schedulable::state
DynamicProcess::get_state() const
{
typedef vector<DynamicThread*>::const_iterator ThreadIt;
static const int uninitialized = -1;
assert(_dynamic_threads.size() > 0);
state result = state_future;
int next_thread_starts_at = uninitialized;
for(ThreadIt it = _dynamic_threads.begin(); it != _dynamic_threads.end(); ++it)
{
state thread_state = (*it)->get_state();
// This is the logic behind the code:
// If there is at least one running thread, the result is
// If there is at least one running thread, the result is
// running. If not, it may be either blocked, ready, future or terminated.
// We have these cases (a state takes precedence over some other one):
// (a) if a thread is running, return immediately state_running
// (b) if a thread is ready, puts unconditionally result as state_ready,
// (b) if a thread is ready, puts unconditionally result as state_ready,
// and continue iterating (to see if there's a running thread)
// (c) if a thread is blocked, and result is not state_ready, result
// (c) if a thread is blocked, and result is not state_ready, result
// becomes state_blocked, and continue iterating (to see if there are
// ready or running threads)
// (d) if a thread is future, and result is not state_ready or
// (d) if a thread is future, and result is not state_ready or
// state_blocked, put result as state_future, and remember
// when the next thread will start (d1) (see at the end of this
// method for the rationale (d2)). Then continue iterating.
// (e) else (if all threads are state_terminated) put result as
// (e) else (if all threads are state_terminated) put result as
// state_terminated.
// TODO Is this OK? Must be tested...
switch(thread_state) {
switch(thread_state)
{
case state_running: // (a)
return state_running;
case state_ready: // (b)
@ -98,9 +98,9 @@ DynamicProcess::get_state() const
result = state_future;
int thread_starts_at = (*it)->get_arrival_time();
if(next_thread_starts_at == uninitialized) // (d1)
next_thread_starts_at = thread_starts_at;
next_thread_starts_at = thread_starts_at;
else
next_thread_starts_at = std::min(thread_starts_at, next_thread_starts_at);
next_thread_starts_at = std::min(thread_starts_at, next_thread_starts_at);
continue;
default: // (e)
result = state_terminated;
@ -108,7 +108,7 @@ DynamicProcess::get_state() const
} //~ "for" iterating over threads
// Now check if a "hole" happens: if result == state_future, but the next
// 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:
@ -121,13 +121,13 @@ DynamicProcess::get_state() const
return result;
}
void
void
DynamicProcess::remove_thread(Thread* thread)
{
assert(thread != NULL);
vector<DynamicThread*>::iterator it;
it = std::find(_dynamic_threads.begin(), _dynamic_threads.end(), thread);
if(it != _dynamic_threads.end())
@ -137,7 +137,7 @@ DynamicProcess::remove_thread(Thread* thread)
// (which is?)
delete *it;
}
}
void
@ -148,9 +148,9 @@ DynamicProcess::add_thread(DynamicThread* thread)
_dynamic_threads.push_back(thread);
}
void
void
DynamicProcess::serialize(SerializeVisitor& translator) const
{
//FIXME write this code. I'm predictable, I know
}