Reformat using clang-format

This commit is contained in:
Matteo Settenvini 2018-09-25 10:20:45 +02:00
parent c1ac6f279b
commit ffd4b6b319
197 changed files with 13059 additions and 13569 deletions

View file

@ -20,248 +20,247 @@
#include "concrete_simulation.hh"
#include <sgpemv2/simulation_observer.hh>
#include <sgpemv2/scheduler.hh>
#include <sgpemv2/cpu_policies_gatekeeper.hh>
#include <sgpemv2/resource_policies_gatekeeper.hh>
#include <sgpemv2/scheduler.hh>
#include <sgpemv2/simulation_observer.hh>
#include <cassert>
#include <algorithm>
#include <cassert>
#include <functional>
#include <string>
#include <iostream>
#include <string>
using namespace sgpem;
ConcreteSimulation::ConcreteSimulation() :
Simulation(), _state(state_stopped),
_mode(mode_continuous), _policy(NULL), _resource_policy(NULL)
ConcreteSimulation::ConcreteSimulation ()
: Simulation (), _state (state_stopped), _mode (mode_continuous), _policy (NULL), _resource_policy (NULL)
{
}
void
ConcreteSimulation::set_mode(const mode new_mode)
ConcreteSimulation::set_mode (const mode new_mode)
{
_mode = new_mode;
_mode = new_mode;
}
Simulation::mode
ConcreteSimulation::get_mode() const
ConcreteSimulation::get_mode () const
{
return _mode;
return _mode;
}
void
ConcreteSimulation::jump_to(History::position p)
ConcreteSimulation::jump_to (History::position p)
{
switch (_state)
{
case state_running:
// pauses the simulation (done below)
switch (_state)
{
case state_running:
// pauses the simulation (done below)
break;
case state_stopped:
_history.set_front(0);
break;
default:
break;
}
case state_stopped:
_history.set_front (0);
break;
default:
break;
}
// Disable momentarily updates for registered observers on
// sgpem::Simulation and sgpem::History.
History::LockNotify h_lock(_history);
Simulation::LockNotify s_lock(*this);
// Disable momentarily updates for registered observers on
// sgpem::Simulation and sgpem::History.
History::LockNotify h_lock (_history);
Simulation::LockNotify s_lock (*this);
pause();
pause ();
bool yet_to_finish = true;
History::position increment = 0;
while (yet_to_finish && p > _history.get_front() + increment)
{
yet_to_finish = step();
increment++;
}
get_history().set_front(std::min(p, _history.get_size()));
bool yet_to_finish = true;
History::position increment = 0;
while (yet_to_finish && p > _history.get_front () + increment)
{
yet_to_finish = step ();
increment++;
}
get_history ().set_front (std::min (p, _history.get_size ()));
if (!yet_to_finish)
stop();
stop ();
}
void
ConcreteSimulation::pause()
ConcreteSimulation::pause ()
{
if(_state != state_paused)
if (_state != state_paused)
{
_state = state_paused;
notify_change();
_state = state_paused;
notify_change ();
}
}
void
ConcreteSimulation::stop()
ConcreteSimulation::stop ()
{
if(_state != state_stopped)
if (_state != state_stopped)
{
_state = state_stopped;
notify_change();
_state = state_stopped;
notify_change ();
}
}
void
ConcreteSimulation::run()
ConcreteSimulation::run ()
{
switch (_state)
{
case state_stopped:
_history.set_front(0);
break;
default:
break;
}
_state = state_running;
//step forward
bool yet_to_finish = step();
_history.set_front(_history.get_front() + 1);
if (yet_to_finish)
switch (_state)
{
if(_mode == mode_step_by_step)
pause();
else
// We remain in running state, and we notify everybody!
// This is non-trivial, and we must do so since we
// put the state to running inconditionally. Don't
// touch this if you don't provide another way to tell
// a SimulationObserver that the simulation advanced
// and *yet* it is in running state!
notify_change();
case state_stopped:
_history.set_front (0);
break;
default:
break;
}
else
// Simulation ended
stop();
_state = state_running;
//step forward
bool yet_to_finish = step ();
_history.set_front (_history.get_front () + 1);
if (yet_to_finish)
{
if (_mode == mode_step_by_step)
pause ();
else
// We remain in running state, and we notify everybody!
// This is non-trivial, and we must do so since we
// put the state to running inconditionally. Don't
// touch this if you don't provide another way to tell
// a SimulationObserver that the simulation advanced
// and *yet* it is in running state!
notify_change ();
}
else
// Simulation ended
stop ();
}
bool
ConcreteSimulation::step()
ConcreteSimulation::step ()
{
if (get_policy() == nullptr)
if (get_policy () == nullptr)
{
stop();
throw NullPolicyException("no CPU policy selected");
stop ();
throw NullPolicyException ("no CPU policy selected");
}
if (get_resource_policy() == nullptr)
if (get_resource_policy () == nullptr)
{
stop();
throw NullPolicyException("no resource policy selected");
stop ();
throw NullPolicyException ("no resource policy selected");
}
try
try
{
// step forward
bool yet_to_finish = true;
if (_history.get_front() == _history.get_size() - 1)
{
if(!_history.is_sealed())
yet_to_finish = Scheduler::get_instance().step_forward(_history, *get_policy(), *get_resource_policy());
else
yet_to_finish = false;
}
// step forward
bool yet_to_finish = true;
if (_history.get_front () == _history.get_size () - 1)
{
if (!_history.is_sealed ())
yet_to_finish = Scheduler::get_instance ().step_forward (_history, *get_policy (), *get_resource_policy ());
else
yet_to_finish = false;
}
if (!yet_to_finish) _history.seal();
if (!yet_to_finish)
_history.seal ();
// since the simulation expects to be notified
// of simulation termination when reaching the last environment
// and the front will be updated just out of this method,
// we have to make this horrible thing
if (_history.get_front() == _history.get_size() - 2 && _history.is_sealed())
yet_to_finish = false;
// since the simulation expects to be notified
// of simulation termination when reaching the last environment
// and the front will be updated just out of this method,
// we have to make this horrible thing
if (_history.get_front () == _history.get_size () - 2 && _history.is_sealed ())
yet_to_finish = false;
return yet_to_finish;
return yet_to_finish;
}
catch (const CPUPolicyException& e)
catch (const CPUPolicyException &e)
{
stop();
throw;
stop ();
throw;
}
}
Simulation::state
ConcreteSimulation::get_state() const
ConcreteSimulation::get_state () const
{
return _state;
return _state;
}
ConcreteHistory&
ConcreteSimulation::get_history()
ConcreteHistory &
ConcreteSimulation::get_history ()
{
return _history;
return _history;
}
const ConcreteHistory&
ConcreteSimulation::get_history() const
const ConcreteHistory &
ConcreteSimulation::get_history () const
{
return _history;
return _history;
}
void
ConcreteSimulation::set_policy(CPUPolicy* p)
ConcreteSimulation::set_policy (CPUPolicy *p)
{
stop();
stop ();
try
{
CPUPoliciesGatekeeper::get_instance().activate_policy(&_history, p);
_policy = p;
}
catch(const CPUPolicyException& e1)
{
try
{
// this is a no-op if _policy is nullptr
CPUPoliciesGatekeeper::get_instance().activate_policy(&_history, _policy);
CPUPoliciesGatekeeper::get_instance ().activate_policy (&_history, p);
_policy = p;
}
catch(const CPUPolicyException& e2)
catch (const CPUPolicyException &e1)
{
_policy = nullptr;
try
{
// this is a no-op if _policy is nullptr
CPUPoliciesGatekeeper::get_instance ().activate_policy (&_history, _policy);
}
catch (const CPUPolicyException &e2)
{
_policy = nullptr;
std::string msg = _("unable to change policy and to restore the previous: ");
msg += e2.what();
std::string msg = _ ("unable to change policy and to restore the previous: ");
msg += e2.what ();
throw CPUPolicyException(msg);
throw CPUPolicyException (msg);
}
std::string msg = _ ("unable to change policy: ");
msg += e1.what ();
throw CPUPolicyException (msg);
}
std::string msg = _("unable to change policy: ");
msg+= e1.what();
throw CPUPolicyException(msg);
}
}
CPUPolicy*
ConcreteSimulation::get_policy()
CPUPolicy *
ConcreteSimulation::get_policy ()
{
return _policy;
return _policy;
}
void
ConcreteSimulation::set_resource_policy(ResourcePolicy* p)
ConcreteSimulation::set_resource_policy (ResourcePolicy *p)
{
stop();
ResourcePoliciesGatekeeper::get_instance().activate_policy(&_history, p);
_resource_policy = p;
stop ();
ResourcePoliciesGatekeeper::get_instance ().activate_policy (&_history, p);
_resource_policy = p;
}
ResourcePolicy*
ConcreteSimulation::get_resource_policy()
ResourcePolicy *
ConcreteSimulation::get_resource_policy ()
{
return _resource_policy;
return _resource_policy;
}