1 /* Copyright (c) 2007-2023. 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/kernel/resource/CpuImpl.hpp"
12 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(ker_actor);
14 namespace simgrid::kernel::activity {
16 SleepImpl& SleepImpl::set_host(s4u::Host* host)
22 SleepImpl& SleepImpl::set_duration(double duration)
28 SleepImpl* SleepImpl::start()
30 model_action_ = host_->get_cpu()->sleep(duration_);
31 model_action_->set_activity(this);
32 XBT_DEBUG("Create sleep synchronization %p", this);
36 void SleepImpl::set_exception(actor::ActorImpl* issuer)
38 /* FIXME: Really, nothing bad can happen while we sleep? */
40 void SleepImpl::finish()
42 if (model_action_->get_state() == resource::Action::State::FAILED) {
43 if (host_ && not host_->is_on())
44 set_state(State::SRC_HOST_FAILURE);
46 set_state(State::CANCELED);
47 } else if (model_action_->get_state() == resource::Action::State::FINISHED) {
48 set_state(State::DONE);
52 XBT_DEBUG("SleepImpl::finish() in state %s", get_state_str());
53 while (not simcalls_.empty()) {
54 const actor::Simcall* simcall = simcalls_.front();
55 simcalls_.pop_front();
57 simcall->issuer_->waiting_synchro_ = nullptr;
58 if (simcall->issuer_->is_suspended()) {
59 XBT_DEBUG("Wait! This actor is suspended and can't wake up now.");
60 simcall->issuer_->suspended_ = false;
61 simcall->issuer_->suspend();
63 simcall->issuer_->simcall_answer();
67 } // namespace simgrid::kernel::activity