1 /* Copyright (c) 2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 /** @file BoostContext.hpp
8 Userspace context switching implementation based on Boost.Context */
10 #ifndef SIMGRID_SIMIX_BOOST_CONTEXT_HPP
11 #define SIMGRID_SIMIX_BOOST_CONTEXT_HPP
15 #include <xbt/parmap.h>
17 #include <simgrid/simix.hpp>
24 class BoostSerialContext;
25 class BoostParallelContext;
26 class BoostContextFactory;
28 class BoostContext : public Context {
30 static bool parallel_;
31 static xbt_parmap_t parmap_;
32 static std::vector<BoostContext*> workers_context_;
33 static unsigned long threads_working_;
34 static xbt_os_thread_key_t worker_id_key_;
35 static unsigned long process_index_;
36 static BoostContext* maestro_context_;
38 #if HAVE_BOOST_CONTEXT == 1
39 boost::context::fcontext_t* fc_ = nullptr;
41 boost::context::fcontext_t fc_;
43 void* stack_ = nullptr;
45 friend BoostContextFactory;
46 BoostContext(std::function<void()> code,
47 void_pfn_smxprocess_t cleanup_func,
48 smx_process_t process);
52 static void wrapper(int first, ...);
55 class BoostContextFactory : public ContextFactory {
58 friend BoostSerialContext;
59 friend BoostParallelContext;
61 BoostContextFactory();
62 virtual ~BoostContextFactory();
63 virtual Context* create_context(std::function<void()> code,
64 void_pfn_smxprocess_t, smx_process_t process) override;
65 void run_all() override;