Logo AND Algorithmique Numérique Distribuée

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