Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Minor sonar smells, and other cosmetics.
[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_ANSWERED",
18     "Simcall::RUN_BLOCKING",
19 }};
20
21 /** @private
22  * @brief (in kernel mode) unpack the simcall and activate the handler
23  *
24  */
25 void simgrid::kernel::actor::ActorImpl::simcall_handle(int times_considered)
26 {
27   XBT_DEBUG("Handling simcall %p: %s", &simcall_, SIMIX_simcall_name(simcall_));
28   if (simcall_.observer_ != nullptr)
29     simcall_.observer_->prepare(times_considered);
30   if (context_->wannadie())
31     return;
32
33   xbt_assert(simcall_.call_ != simgrid::simix::Simcall::NONE, "Asked to do the noop syscall on %s@%s", get_cname(),
34              get_host()->get_cname());
35
36   (*simcall_.code_)();
37   if (simcall_.call_ == simgrid::simix::Simcall::RUN_ANSWERED)
38     simcall_answer();
39 }
40
41 /** @brief returns a printable string representing a simcall */
42 const char* SIMIX_simcall_name(const s_smx_simcall& simcall)
43 {
44   if (simcall.observer_ != nullptr) {
45     static std::string name;
46     name              = boost::core::demangle(typeid(*simcall.observer_).name());
47     const char* cname = name.c_str();
48     if (name.rfind("simgrid::kernel::", 0) == 0)
49       cname += 17; // strip prefix "simgrid::kernel::"
50     return cname;
51   } else {
52     return simcall_names.at(static_cast<int>(simcall.call_));
53   }
54 }