Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
adca9a2e9fbce32b226cc62c0d4ef9b79acb1a4c
[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 /* Boost uses undef preprocessor symbols on FreeBSD, so disable our Werror for this file */
10 #ifdef __clang__
11 #pragma clang diagnostic push
12 #pragma clang diagnostic ignored "-Wundef"
13 #endif
14
15 #include <boost/version.hpp>
16 #if BOOST_VERSION < 106100
17 #include <boost/context/fcontext.hpp>
18 #else
19 #include <boost/context/detail/fcontext.hpp>
20 #endif
21
22 #ifdef __clang__
23 #pragma clang diagnostic pop
24 #endif
25
26 #include <atomic>
27 #include <cstdint>
28 #include <functional>
29 #include <vector>
30
31 #include "src/kernel/context/ContextSwapped.hpp"
32 #include "src/xbt/parmap.hpp"
33
34 namespace simgrid::kernel::context {
35
36 /** @brief Userspace context switching implementation based on Boost.Context */
37 class BoostContext : public SwappedContext {
38 public:
39   BoostContext(std::function<void()>&& code, actor::ActorImpl* actor, SwappedContextFactory* factory);
40
41 private:
42 #if BOOST_VERSION < 106100
43   boost::context::fcontext_t fc_{};
44   using arg_type = intptr_t;
45 #else
46   boost::context::detail::fcontext_t fc_{};
47   using arg_type = boost::context::detail::transfer_t;
48 #endif
49
50   XBT_ATTRIB_NORETURN static void wrapper(arg_type arg);
51
52   void swap_into_for_real(SwappedContext* to) override;
53 };
54
55 class BoostContextFactory : public SwappedContextFactory {
56 public:
57   BoostContext* create_context(std::function<void()>&& code, actor::ActorImpl* actor) override;
58 };
59 } // namespace simgrid::kernel::context
60
61 #endif