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>
21 class BoostSerialContext;
22 class BoostParallelContext;
23 class BoostContextFactory;
25 /** @brief Userspace context switching implementation based on Boost.Context */
26 class BoostContext : public Context {
28 static bool parallel_;
29 static xbt_parmap_t parmap_;
30 static std::vector<BoostContext*> workers_context_;
31 static uintptr_t threads_working_;
32 static xbt_os_thread_key_t worker_id_key_;
33 static unsigned long process_index_;
34 static BoostContext* maestro_context_;
36 #if HAVE_BOOST_CONTEXTS == 1
37 boost::context::fcontext_t* fc_ = nullptr;
39 boost::context::fcontext_t fc_;
41 void* stack_ = nullptr;
43 friend BoostContextFactory;
44 BoostContext(std::function<void()> code,
45 void_pfn_smxprocess_t cleanup_func,
46 smx_process_t process);
47 ~BoostContext() override;
48 virtual void resume();
50 static void wrapper(int first, ...);
53 class BoostContextFactory : public ContextFactory {
56 friend BoostSerialContext;
57 friend BoostParallelContext;
59 BoostContextFactory();
60 ~BoostContextFactory() override;
61 Context* create_context(std::function<void()> code,
62 void_pfn_smxprocess_t, smx_process_t process) override;
63 void run_all() override;