Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill popping_{enum,generated}
[simgrid.git] / src / simix / popping.cpp
1 /* Copyright (c) 2010-2022. 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 "simgrid/s4u/Host.hpp"
7 #include "src/kernel/actor/ActorImpl.hpp"
8 #include "src/kernel/actor/SimcallObserver.hpp"
9 #include "src/kernel/context/Context.hpp"
10 #include "src/simix/popping_private.hpp"
11 #include "xbt/log.h"
12
13 XBT_LOG_NEW_DEFAULT_CATEGORY(simix, "transmuting from user request into kernel handlers");
14
15 constexpr std::array<const char*, simgrid::simix::NUM_SIMCALLS> simcall_names{{
16     "Simcall::NONE",
17     "Simcall::RUN_KERNEL",
18     "Simcall::RUN_BLOCKING",
19 }};
20
21 /** @private
22  * @brief (in kernel mode) unpack the simcall and activate the handler
23  *
24  * This function is generated from src/simix/simcalls.in
25  */
26 void simgrid::kernel::actor::ActorImpl::simcall_handle(int times_considered)
27 {
28   XBT_DEBUG("Handling simcall %p: %s", &simcall_, SIMIX_simcall_name(simcall_));
29   if (simcall_.observer_ != nullptr)
30     simcall_.observer_->prepare(times_considered);
31   if (context_->wannadie())
32     return;
33   switch (simcall_.call_) {
34     case simgrid::simix::Simcall::RUN_KERNEL:
35       SIMIX_run_kernel(simcall_.code_);
36       simcall_answer();
37       break;
38
39     case simgrid::simix::Simcall::RUN_BLOCKING:
40       SIMIX_run_blocking(simcall_.code_);
41       break;
42
43     case simgrid::simix::Simcall::NONE:
44       throw std::invalid_argument(
45           simgrid::xbt::string_printf("Asked to do the noop syscall on %s@%s", get_cname(), get_host()->get_cname()));
46     default:
47       THROW_IMPOSSIBLE;
48   }
49 }
50
51 void SIMIX_run_kernel(std::function<void()> const* code)
52 {
53   (*code)();
54 }
55
56 /** Kernel code for run_blocking
57  *
58  * The implementation looks a lot like SIMIX_run_kernel ^^
59  *
60  * However, this `run_blocking` is blocking so the process will not be woken
61  * up until `ActorImpl::simcall_answer()`` is called by the kernel.
62  * This means that `code` is responsible for doing this.
63  */
64 void SIMIX_run_blocking(std::function<void()> const* code)
65 {
66   (*code)();
67 }