1 /* Copyright (c) 2007-2019. 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 "src/kernel/activity/SleepImpl.hpp"
7 #include "simgrid/Exception.hpp"
8 #include "simgrid/kernel/resource/Action.hpp"
9 #include "simgrid/s4u/Host.hpp"
10 #include "src/kernel/context/Context.hpp"
11 #include "src/simix/popping_private.hpp"
12 #include "src/simix/smx_private.hpp"
13 #include "src/surf/cpu_interface.hpp"
14 #include "src/surf/surf_interface.hpp"
16 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_process);
21 SleepImpl& SleepImpl::set_host(s4u::Host* host)
27 SleepImpl& SleepImpl::set_duration(double duration)
33 SleepImpl* SleepImpl::start()
35 surf_action_ = host_->pimpl_cpu->sleep(duration_);
36 surf_action_->set_activity(this);
37 XBT_DEBUG("Create sleep synchronization %p", this);
41 void SleepImpl::post()
43 if (surf_action_->get_state() == resource::Action::State::FAILED) {
44 if (host_ && not host_->is_on())
45 state_ = SIMIX_SRC_HOST_FAILURE;
47 state_ = SIMIX_CANCELED;
48 } else if (surf_action_->get_state() == resource::Action::State::FINISHED) {
54 void SleepImpl::finish()
56 while (not simcalls_.empty()) {
57 smx_simcall_t simcall = simcalls_.front();
58 simcalls_.pop_front();
60 simcall->issuer_->waiting_synchro = nullptr;
61 if (simcall->issuer_->is_suspended()) {
62 XBT_DEBUG("Wait! This process is suspended and can't wake up now.");
63 simcall->issuer_->suspended_ = false;
64 simcall->issuer_->suspend(simcall->issuer_);
66 simcall->issuer_->simcall_answer();
72 } // namespace activity
74 } // namespace simgrid