Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
e13262198488dd172c0c9d202126288d54952407
[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 namespace simgrid {
12 namespace kernel {
13 namespace context {
14
15 class SwappedContext : public Context {
16 public:
17   SwappedContext(std::function<void()> code, void_pfn_smxprocess_t cleanup_func, smx_actor_t process);
18   virtual ~SwappedContext();
19
20   virtual void suspend();
21   virtual void resume();
22
23   static void run_all();
24
25   virtual void swap_into(SwappedContext* to) = 0;
26
27   static SwappedContext* get_maestro() { return maestro_context_; }
28   static void set_maestro(SwappedContext* maestro) { maestro_context_ = maestro; }
29
30 protected:
31   void* stack_ = nullptr; /* the thread stack */
32
33 private:
34   static unsigned long process_index_;
35   static SwappedContext* maestro_context_;
36 };
37
38 } // namespace context
39 } // namespace kernel
40 } // namespace simgrid
41 #endif