};
enum class SuspendStates {
- not_suspended = 0, /**< Action currently not suspended **/
- suspended,
- sleeping
+ RUNNING = 0, /**< Action currently not suspended **/
+ SUSPENDED,
+ SLEEPING
};
/**
/** @brief Resume the current Action */
virtual void resume();
+ /** @brief Returns true if the current action is suspended */
+ bool is_suspended() const { return suspended_ == SuspendStates::SUSPENDED; }
/** @brief Returns true if the current action is running */
- bool is_suspended();
+ bool is_running() const { return suspended_ == SuspendStates::RUNNING; }
/** @brief Get the maximum duration of the current action */
double get_max_duration() const { return max_duration_; }
simgrid::kernel::resource::Model* get_model() const { return model_; }
-protected:
- StateSet* state_set_;
-
private:
+ StateSet* state_set_;
+ Action::SuspendStates suspended_ = Action::SuspendStates::RUNNING;
int refcount_ = 1;
double sharing_priority_ = 1.0; /**< priority (1.0 by default) */
double max_duration_ = NO_MAX_DURATION; /*< max_duration (may fluctuate until the task is completed) */
double get_last_value() const { return last_value_; }
void set_last_value(double val) { last_value_ = val; }
+ void set_suspend_state(Action::SuspendStates state) { suspended_ = state; }
protected:
- Action::SuspendStates suspended_ = Action::SuspendStates::not_suspended;
};
} // namespace resource
void Action::suspend()
{
XBT_IN("(%p)", this);
- if (suspended_ != SuspendStates::sleeping) {
+ if (suspended_ != SuspendStates::SLEEPING) {
get_model()->get_maxmin_system()->update_variable_weight(get_variable(), 0.0);
if (get_model()->get_update_algorithm() == Model::UpdateAlgo::LAZY) {
get_model()->get_action_heap().remove(this);
update_remains_lazy(surf_get_clock());
}
}
- suspended_ = SuspendStates::suspended;
+ suspended_ = SuspendStates::SUSPENDED;
}
XBT_OUT();
}
void Action::resume()
{
XBT_IN("(%p)", this);
- if (suspended_ != SuspendStates::sleeping) {
+ if (suspended_ != SuspendStates::SLEEPING) {
get_model()->get_maxmin_system()->update_variable_weight(get_variable(), get_priority());
- suspended_ = SuspendStates::not_suspended;
+ suspended_ = SuspendStates::RUNNING;
if (get_model()->get_update_algorithm() == Model::UpdateAlgo::LAZY)
get_model()->get_action_heap().remove(this);
}
XBT_OUT();
}
-bool Action::is_suspended()
-{
- return suspended_ == SuspendStates::suspended;
-}
-
double Action::get_remains()
{
XBT_IN("(%p)", this);
// FIXME: sleep variables should not consume 1.0 in System::expand()
action->set_max_duration(duration);
- action->suspended_ = kernel::resource::Action::SuspendStates::sleeping;
+ action->set_suspend_state(kernel::resource::Action::SuspendStates::SLEEPING);
if (duration == NO_MAX_DURATION)
action->set_state(simgrid::kernel::resource::Action::State::IGNORED);
continue;
/* action suspended, skip it */
- if (action.suspended_ != kernel::resource::Action::SuspendStates::not_suspended)
+ if (not action.is_running())
continue;
sum_priority_ += 1.0 / action.get_priority();
continue;
/* verify if the action is really running on cpu */
- if (action.suspended_ == kernel::resource::Action::SuspendStates::not_suspended && action.get_priority() > 0) {
+ if (action.is_running() && action.get_priority() > 0) {
/* total area needed to finish the action. Used in trace integration */
double total_area = (action.get_remains() * sum_priority_ * action.get_priority()) / speed_.peak;
continue;
/* action suspended, skip it */
- if (action.suspended_ != kernel::resource::Action::SuspendStates::not_suspended)
+ if (not action.is_running())
continue;
/* action don't need update */
CpuTiAction* action = new CpuTiAction(this, 1.0);
action->set_max_duration(duration);
- action->suspended_ = kernel::resource::Action::SuspendStates::sleeping;
+ action->set_suspend_state(kernel::resource::Action::SuspendStates::SLEEPING);
if (duration == NO_MAX_DURATION)
action->set_state(simgrid::kernel::resource::Action::State::IGNORED);
void CpuTiAction::suspend()
{
XBT_IN("(%p)", this);
- if (suspended_ != Action::SuspendStates::sleeping) {
- suspended_ = Action::SuspendStates::suspended;
+ if (is_running()) {
+ set_suspend_state(Action::SuspendStates::SUSPENDED);
get_model()->get_action_heap().remove(this);
cpu_->set_modified(true);
}
void CpuTiAction::resume()
{
XBT_IN("(%p)", this);
- if (suspended_ != Action::SuspendStates::sleeping) {
- suspended_ = Action::SuspendStates::not_suspended;
+ if (is_suspended()) {
+ set_suspend_state(Action::SuspendStates::RUNNING);
cpu_->set_modified(true);
}
XBT_OUT();
void NetworkCm02Action::update_remains_lazy(double now)
{
- if (suspended_ != Action::SuspendStates::not_suspended)
+ if (not is_running())
return;
- double delta = now - get_last_update();
+ double delta = now - get_last_update();
if (get_remains_no_update() > 0) {
XBT_DEBUG("Updating action(%p): remains was %f, last_update was: %f", this, get_remains_no_update(),
{
L07Action *action = static_cast<L07Action*>(execution_start(1.0));
action->set_max_duration(duration);
- action->suspended_ = kernel::resource::Action::SuspendStates::sleeping;
+ action->set_suspend_state(kernel::resource::Action::SuspendStates::SLEEPING);
get_model()->get_maxmin_system()->update_variable_weight(action->get_variable(), 0.0);
return action;
}
double lat_bound = kernel::resource::NetworkModel::cfg_tcp_gamma / (2.0 * lat_current);
XBT_DEBUG("action (%p) : lat_bound = %g", this, lat_bound);
- if ((latency_ <= 0.0) && (suspended_ == Action::SuspendStates::not_suspended)) {
+ if ((latency_ <= 0.0) && is_running()) {
if (rate_ < 0)
get_model()->get_maxmin_system()->update_variable_bound(get_variable(), lat_bound);
else
void StorageN11Action::suspend()
{
XBT_IN("(%p)", this);
- if (suspended_ != Action::SuspendStates::sleeping) {
+ if (is_running()) {
get_model()->get_maxmin_system()->update_variable_weight(get_variable(), 0.0);
- suspended_ = Action::SuspendStates::suspended;
+ set_suspend_state(Action::SuspendStates::SUSPENDED);
}
XBT_OUT();
}