Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Move Parallel{Boost,Raw,U}Context::{initialize,finalize} to SwappedContext
[simgrid.git] / src / kernel / context / ContextSwapped.hpp
1 /* Copyright (c) 2009-2018. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #ifndef SIMGRID_SIMIX_SWAPPED_CONTEXT_HPP
7 #define SIMGRID_SIMIX_SWAPPED_CONTEXT_HPP
8
9 #include "src/kernel/context/Context.hpp"
10
11 #include <vector>
12
13 namespace simgrid {
14 namespace kernel {
15 namespace context {
16
17 class SwappedContext : public Context {
18 public:
19   SwappedContext(std::function<void()> code, void_pfn_smxprocess_t cleanup_func, smx_actor_t process);
20   virtual ~SwappedContext();
21
22   static void initialize(); // Initialize the module, using the options
23   static void finalize();   // Finalize the module
24
25   virtual void suspend();
26   virtual void resume();
27
28   static void run_all();
29
30   virtual void swap_into(SwappedContext* to) = 0; // Defined in subclasses
31
32   static SwappedContext* get_maestro() { return maestro_context_; }
33   static void set_maestro(SwappedContext* maestro) { maestro_context_ = maestro; }
34
35 protected:
36   void* stack_ = nullptr; /* the thread stack */
37
38   /* For the parallel execution */
39   static simgrid::xbt::Parmap<smx_actor_t>* parmap_;
40   static std::vector<SwappedContext*> workers_context_;
41   static std::atomic<uintptr_t> threads_working_;
42   static thread_local uintptr_t worker_id_;
43
44 private:
45   static unsigned long process_index_;
46   static SwappedContext* maestro_context_;
47 };
48
49 } // namespace context
50 } // namespace kernel
51 } // namespace simgrid
52 #endif