Logo AND Algorithmique Numérique Distribuée

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