Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[simix] Move BoostContext to C++
[simgrid.git] / src / simix / BoostContext.hpp
1 /* Copyright (c) 2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 /** @file BoostContext.hpp
8     Userspace context switching implementation based on Boost.Context */
9
10 #ifndef SIMGRID_SIMIX_BOOST_CONTEXT_HPP
11 #define SIMGRID_SIMIX_BOOST_CONTEXT_HPP
12
13 #include <vector>
14
15 #include <xbt/parmap.h>
16
17 #include <simgrid/simix.hpp>
18
19
20 namespace simgrid {
21 namespace simix {
22
23 class BoostContext;
24 class BoostSerialContext;
25 class BoostParallelContext;
26 class BoostContextFactory;
27
28 class BoostContext : public Context {
29 protected: // static
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_;
37 protected:
38 #if HAVE_BOOST_CONTEXT == 1
39   boost::context::fcontext_t* fc_ = nullptr;
40 #else
41   boost::context::fcontext_t fc_;
42 #endif
43   void* stack_ = nullptr;
44 public:
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);
50   ~BoostContext();
51   void resume();
52 };
53
54 class BoostContextFactory : public ContextFactory {
55 public:
56   friend BoostContext;
57   friend BoostSerialContext;
58   friend BoostParallelContext;
59
60   BoostContextFactory();
61   virtual ~BoostContextFactory();
62   virtual Context* create_context(
63     xbt_main_func_t, int, char **, void_pfn_smxprocess_t,
64     smx_process_t process
65     ) override;
66   void run_all() override;
67 };
68
69 }
70 }
71
72 #endif