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(xbt_main_func_t code,
47 int argc, char **argv,
48 void_pfn_smxprocess_t cleanup_func,
49 smx_process_t process);
54 class BoostContextFactory : public ContextFactory {
57 friend BoostSerialContext;
58 friend BoostParallelContext;
60 BoostContextFactory();
61 virtual ~BoostContextFactory();
62 virtual Context* create_context(
63 xbt_main_func_t, int, char **, void_pfn_smxprocess_t,
66 void run_all() override;