sgpemv2/src/backend/resource_policy_lifo.cc
matrevis 68d5f30f64 - Defaults to thread view.
- Enforcing resource policy the old way.


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1016 3ecf2c5c-341e-0410-92b4-d18e462d057c
2006-09-06 00:29:11 +00:00

106 lines
2.5 KiB
C++

// src/backend/resource_policy_lifo.cc - Copyright 2005, 2006, University
// of Padova, dept. of Pure and Applied
// Mathematics
//
// This file is part of SGPEMv2.
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// SGPEMv2 is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with SGPEMv2; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "resource_policy_lifo.hh"
using namespace std;
using namespace sgpem;
ResourcePolicyLiFo::~ResourcePolicyLiFo()
{}
PolicyParameters&
ResourcePolicyLiFo::get_parameters()
{
return _parameters;
}
void
ResourcePolicyLiFo::configure()
throw(UserInterruptException)
{
}
void
ResourcePolicyLiFo::enforce(Environment& environment, Environment::SubRequestQueue& queue, SubRequest& sr)
throw(UserInterruptException)
{
typedef Environment::SubRequestQueue SubRequestQueue;
printf("\nResourcePolicy 'LiFo' has been called.");
// the last inserted request goes on the first free place.
SubRequestQueue old_queue(queue);
queue.clear();
typedef SubRequestQueue::iterator It;
for (It i = old_queue.begin(); i != old_queue.end(); i++)
{
// allocated ones remain allocated
if((**i).get_state() == Request::state_allocated)
queue.push_back(*i);
}
bool inserted = false;
typedef SubRequestQueue::iterator It;
for (It i = old_queue.begin(); i != old_queue.end(); i++)
{
// allocated ones remain allocated
if((**i).get_state() != Request::state_allocated)
{
// non-allocated ones go after the newly arrived
if(!inserted)
{
queue.push_back(&sr);
inserted = true;
}
if (*i != &sr)
queue.push_back(*i);
}
}
printf("\nResourcePolicy 'LiFo' has terminated.");
}
Glib::ustring
ResourcePolicyLiFo::get_description() const
{
return "A resource policy which allows a request to be immediately allocated if there is enough space.";
}
Glib::ustring
ResourcePolicyLiFo::get_name() const
{
return "Last In, First Out";
}
void
ResourcePolicyLiFo::activate()
{
}
void
ResourcePolicyLiFo::deactivate()
{
}