- Simplify a little sequences' interface

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1028 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-09-06 17:39:46 +00:00
parent c62734ef59
commit 8e20f5499f
11 changed files with 60 additions and 78 deletions

View file

@ -19,7 +19,7 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
// DISCLAIMER FOR THE RAMPANT CODER:
// DISCLAIMER FOR THE RAMPANT CODER: \\
// ----------------------------------------------------\\
// ``If you touch this code, your ass is grass, \\
// and I'm the lawnmover.'' \\
@ -70,7 +70,7 @@ static void raise_new_requests(DynamicThread& running_thread, ConcreteEnvironmen
static void look_for_mutant_request_states(ConcreteEnvironment& environment, unsigned int& alive_threads);
static void determine_subr_allocable_status(const DynamicRequest& req, DynamicSubRequest& subr,
const Resource& res, SubRequestQueue& queue);
static void determine_subr_allocable_status(const Resource& res, SubRequestQueue& queue);
static void determine_subr_allocable_status(const Resource& res, const SubRequestQueue& queue);
// ---------------------------------------------------------
@ -89,7 +89,7 @@ collect_threads(const std::vector<Process*>& procs,
Threads& collected_threads)
{
collected_threads.clear();
for (Iseq<vector<Process*>::const_iterator> seq = const_iseq(procs); seq; ++seq)
for (Iseq<vector<Process*>::const_iterator> seq = iseq(procs); seq; ++seq)
{
const Threads& ts = ((DynamicProcess&) **seq).get_dynamic_threads();
collected_threads.insert(collected_threads.end(), ts.begin(), ts.end());
@ -103,7 +103,7 @@ prepare_ready_queue(ConcreteEnvironment& snapshot,
{
ReadyQueue& queue = snapshot.get_sorted_queue();
assert(queue.size() == 0);
for (Iseq<Threads::const_iterator> seq = const_iseq(all_threads); seq; ++seq)
for (Iseq<Threads::const_iterator> seq = iseq(all_threads); seq; ++seq)
{
if ((*seq)->get_state() == Schedulable::state_ready)
queue.append(**seq);
@ -228,27 +228,30 @@ raise_new_requests(DynamicThread& running_thread, ConcreteEnvironment& environme
switch(cur_req.get_state())
{
case Request::state_allocable:
for(Iseq<SubRequests::const_iterator> it_dsrs = const_iseq(subreqs); it_dsrs; ++it_dsrs)
{
DynamicSubRequest& subreq = **it_dsrs;
assert(subreq.get_state() == Request::state_allocable);
/*
// Move this request up the queue, to the back of the allocated
// subrequests. This is mainly for display. :-)
// The rest of the queue sorting business is up to the resource policy.
Environment::resource_key_t rkey = subreq.get_resource_key();
SubRequestQueue& queue = environment.get_request_queue(rkey);
assert(queue.size() > 0);
SubRequestQueue::iterator alloc_it = queue.begin();
for(; (*alloc_it)->get_state() == Request::state_allocated; ++alloc_it)
{
const SubRequests& const_subreqs = subreqs;
for(Iseq<SubRequests::const_iterator> it_dsrs = iseq(const_subreqs); it_dsrs; ++it_dsrs)
{
DynamicSubRequest& subreq = **it_dsrs;
assert(subreq.get_state() == Request::state_allocable);
/*
// Move this request up the queue, to the back of the allocated
// subrequests. This is mainly for display. :-)
// The rest of the queue sorting business is up to the resource policy.
Environment::resource_key_t rkey = subreq.get_resource_key();
SubRequestQueue& queue = environment.get_request_queue(rkey);
assert(queue.size() > 0);
SubRequestQueue::iterator alloc_it = queue.begin();
for(; (*alloc_it)->get_state() == Request::state_allocated; ++alloc_it)
assert(alloc_it != queue.end()); // We cannot reach the end without having found the current subr!
SubRequestQueue::iterator this_subreq = find(alloc_it, queue.end(), &subreq);
assert(this_subreq != queue.end());
swap(*alloc_it, *this_subreq);
*/
subreq.set_state(Request::state_allocated);
}
SubRequestQueue::iterator this_subreq = find(alloc_it, queue.end(), &subreq);
assert(this_subreq != queue.end());
swap(*alloc_it, *this_subreq);
*/
subreq.set_state(Request::state_allocated);
}
}
break;
case Request::state_unallocable:
@ -278,7 +281,8 @@ determine_subr_allocable_status(const DynamicRequest& req, DynamicSubRequest& su
unsigned int position_in_queue = 0;
bool too_far_in_the_queue = false;
for(Iseq<SubRequestQueue::const_iterator> queue_it = const_iseq(queue);
const SubRequestQueue& const_queue = queue;
for(Iseq<SubRequestQueue::const_iterator> queue_it = iseq(const_queue);
queue_it && free_places >= needed_places; queue_it++, position_in_queue++)
{
SubRequest& sr = **queue_it;
@ -329,11 +333,11 @@ determine_subr_allocable_status(const DynamicRequest& req, DynamicSubRequest& su
// The following loop updates the states of the subrequests depending
// on their position in the queue
void
determine_subr_allocable_status(const Resource& res, SubRequestQueue& queue)
determine_subr_allocable_status(const Resource& res, const SubRequestQueue& queue)
{
unsigned int total_places = res.get_places();
unsigned int position_in_queue = 0;
for(Iseq<SubRequestQueue::const_iterator> queue_it = const_iseq(queue);
for(Iseq<SubRequestQueue::const_iterator> queue_it = iseq(queue);
queue_it; queue_it++, position_in_queue++)
{
DynamicSubRequest& sr = (DynamicSubRequest&) **queue_it;