1 /* Copyright (c) 2007-2021. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include <simgrid/s4u/Host.hpp>
8 #include "src/kernel/activity/SleepImpl.hpp"
9 #include "src/kernel/actor/ActorImpl.hpp"
10 #include "src/simix/popping_private.hpp"
11 #include "src/surf/cpu_interface.hpp"
13 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_process);
18 SleepImpl& SleepImpl::set_host(s4u::Host* host)
24 SleepImpl& SleepImpl::set_duration(double duration)
30 SleepImpl* SleepImpl::start()
32 surf_action_ = host_->get_cpu()->sleep(duration_);
33 surf_action_->set_activity(this);
34 XBT_DEBUG("Create sleep synchronization %p", this);
38 void SleepImpl::post()
40 if (surf_action_->get_state() == resource::Action::State::FAILED) {
41 if (host_ && not host_->is_on())
42 state_ = State::SRC_HOST_FAILURE;
44 state_ = State::CANCELED;
45 } else if (surf_action_->get_state() == resource::Action::State::FINISHED) {
50 /* Answer all simcalls associated with the synchro */
54 void SleepImpl::finish()
56 XBT_DEBUG("SleepImpl::finish() in state %s", to_c_str(state_));
57 while (not simcalls_.empty()) {
58 const s_smx_simcall* simcall = simcalls_.front();
59 simcalls_.pop_front();
61 simcall->issuer_->waiting_synchro_ = nullptr;
62 if (simcall->issuer_->is_suspended()) {
63 XBT_DEBUG("Wait! This actor is suspended and can't wake up now.");
64 simcall->issuer_->suspended_ = false;
65 simcall->issuer_->suspend();
67 simcall->issuer_->simcall_answer();
71 } // namespace activity
73 } // namespace simgrid