1 /* Copyright (c) 2015. The SimGrid Team. All rights reserved. */
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. */
6 #ifndef SIMGRID_SIMIX_BOOST_CONTEXT_HPP
7 #define SIMGRID_SIMIX_BOOST_CONTEXT_HPP
12 #include <xbt/parmap.h>
14 #include <simgrid/simix.hpp>
22 class BoostSerialContext;
23 class BoostParallelContext;
24 class BoostContextFactory;
26 /** @brief Userspace context switching implementation based on Boost.Context */
27 class BoostContext : public Context {
29 static bool parallel_;
30 static xbt_parmap_t parmap_;
31 static std::vector<BoostContext*> workers_context_;
32 static uintptr_t threads_working_;
33 static xbt_os_thread_key_t worker_id_key_;
34 static unsigned long process_index_;
35 static BoostContext* maestro_context_;
37 #if HAVE_BOOST_CONTEXTS == 1
38 boost::context::fcontext_t* fc_ = nullptr;
40 boost::context::fcontext_t fc_;
42 void* stack_ = nullptr;
44 friend BoostContextFactory;
45 BoostContext(std::function<void()> code,
46 void_pfn_smxprocess_t cleanup_func,
48 ~BoostContext() override;
49 virtual void resume();
51 static void wrapper(int first, ...);
54 class BoostContextFactory : public ContextFactory {
57 friend BoostSerialContext;
58 friend BoostParallelContext;
60 BoostContextFactory();
61 ~BoostContextFactory() override;
62 Context* create_context(std::function<void()> code,
63 void_pfn_smxprocess_t, smx_actor_t process) override;
64 void run_all() override;