Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
The creation of the pimpl needs no simcall
[simgrid.git] / src / kernel / activity / SleepImpl.cpp
1 /* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved.          */
2
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. */
5
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/ActorImpl.hpp"
12 #include "src/simix/popping_private.hpp"
13 #include "src/simix/smx_private.hpp"
14 #include "src/surf/cpu_interface.hpp"
15 #include "src/surf/surf_interface.hpp"
16
17 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_process);
18 namespace simgrid {
19 namespace kernel {
20 namespace activity {
21
22 SleepImpl::~SleepImpl()
23 {
24   if (surf_action_)
25     surf_action_->unref();
26   XBT_DEBUG("Destroy activity %p", this);
27 }
28
29 SleepImpl* SleepImpl::start(double duration)
30 {
31   surf_action_ = host_->pimpl_cpu->sleep(duration);
32   surf_action_->set_data(this);
33   XBT_DEBUG("Create sleep synchronization %p", this);
34   return this;
35 }
36
37 void SleepImpl::post()
38 {
39   while (not simcalls_.empty()) {
40     smx_simcall_t simcall = simcalls_.front();
41     simcalls_.pop_front();
42     e_smx_state_t result;
43     if (host_ && not host_->is_on()) {
44       /* If the host running the synchro failed, notice it. This way, the asking
45        * actor can be killed if it runs on that host itself */
46       result = SIMIX_SRC_HOST_FAILURE;
47       simcall->issuer->throw_exception(
48           std::make_exception_ptr(simgrid::HostFailureException(XBT_THROW_POINT, "Host failed")));
49     }
50
51     switch (surf_action_->get_state()) {
52       case resource::Action::State::FAILED:
53         simcall->issuer->context_->iwannadie = true;
54         result                               = SIMIX_FAILED;
55         break;
56
57       case resource::Action::State::FINISHED:
58         result = SIMIX_DONE;
59         break;
60
61       default:
62         THROW_IMPOSSIBLE;
63     }
64     if (not simcall->issuer->get_host()->is_on()) {
65       simcall->issuer->context_->iwannadie = true;
66     }
67     simcall_process_sleep__set__result(simcall, result);
68     simcall->issuer->waiting_synchro = nullptr;
69     if (simcall->issuer->is_suspended()) {
70       XBT_DEBUG("Wait! This process is suspended and can't wake up now.");
71       simcall->issuer->suspended_ = false;
72       simcall_HANDLER_process_suspend(simcall, simcall->issuer);
73     } else {
74       SIMIX_simcall_answer(simcall);
75     }
76   }
77
78   SIMIX_process_sleep_destroy(this);
79 }
80 void SleepImpl::finish()
81 {
82   /* FIXME some part of post should move to finish */
83 }
84 } // namespace activity
85 } // namespace kernel
86 } // namespace simgrid