Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fcd54895a9992cb951c4b5a0016f67f8e70aeffd
[simgrid.git] / src / kernel / context / ContextBoost.hpp
1 /* Copyright (c) 2015-2023. 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 #ifndef SIMGRID_KERNEL_CONTEXT_BOOST_CONTEXT_HPP
7 #define SIMGRID_KERNEL_CONTEXT_BOOST_CONTEXT_HPP
8
9 #include <boost/version.hpp>
10 #if BOOST_VERSION < 106100
11 #include <boost/context/fcontext.hpp>
12 #else
13 #include <boost/context/detail/fcontext.hpp>
14 #endif
15
16 #include <atomic>
17 #include <cstdint>
18 #include <functional>
19 #include <vector>
20
21 #include <simgrid/simix.hpp>
22 #include <xbt/parmap.hpp>
23
24 #include "src/internal_config.h"
25 #include "src/kernel/context/ContextSwapped.hpp"
26
27 namespace simgrid::kernel::context {
28
29 /** @brief Userspace context switching implementation based on Boost.Context */
30 class BoostContext : public SwappedContext {
31 public:
32   BoostContext(std::function<void()>&& code, actor::ActorImpl* actor, SwappedContextFactory* factory);
33
34 private:
35 #if BOOST_VERSION < 106100
36   boost::context::fcontext_t fc_{};
37   using arg_type = intptr_t;
38 #else
39   boost::context::detail::fcontext_t fc_{};
40   using arg_type = boost::context::detail::transfer_t;
41 #endif
42
43   XBT_ATTRIB_NORETURN static void wrapper(arg_type arg);
44
45   void swap_into_for_real(SwappedContext* to) override;
46 };
47
48 class BoostContextFactory : public SwappedContextFactory {
49 public:
50   BoostContext* create_context(std::function<void()>&& code, actor::ActorImpl* actor) override;
51 };
52 } // namespace simgrid::kernel::context
53
54 #endif