X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/4d5c6aed22b8ae1c8a73cd04d8ab800322d177bf..15f9e0adbd11d2a0736440004a2f71ef9cfccab8:/src/kernel/context/ContextSwapped.hpp diff --git a/src/kernel/context/ContextSwapped.hpp b/src/kernel/context/ContextSwapped.hpp index 8b5188d941..2794f4a140 100644 --- a/src/kernel/context/ContextSwapped.hpp +++ b/src/kernel/context/ContextSwapped.hpp @@ -6,31 +6,60 @@ #ifndef SIMGRID_SIMIX_SWAPPED_CONTEXT_HPP #define SIMGRID_SIMIX_SWAPPED_CONTEXT_HPP -#include "Context.hpp" +#include "src/kernel/context/Context.hpp" + +#include namespace simgrid { namespace kernel { namespace context { +class SwappedContext; + +class SwappedContextFactory : public ContextFactory { + friend SwappedContext; // Reads whether we are in parallel mode +public: + SwappedContextFactory(std::string name); + ~SwappedContextFactory() override; + void run_all() override; + +protected: + bool parallel_; + +private: + unsigned long process_index_ = 0; // Next actor to execute during sequential run_all() +}; class SwappedContext : public Context { public: - SwappedContext(std::function code, void_pfn_smxprocess_t cleanup_func, smx_actor_t process) - : Context(std::move(code), cleanup_func, process) - { - } - virtual void suspend(); - virtual void resume(); + SwappedContext(std::function code, void_pfn_smxprocess_t cleanup_func, smx_actor_t process, + SwappedContextFactory* factory); + virtual ~SwappedContext(); + + static void initialize(bool parallel); // Initialize the module, using the options + static void finalize(); // Finalize the module - static void run_all(); + void suspend() override; + virtual void resume(); + void stop() override; - virtual void swap_into(SwappedContext* to) = 0; + virtual void swap_into(SwappedContext* to) = 0; // Defined in subclasses static SwappedContext* get_maestro() { return maestro_context_; } static void set_maestro(SwappedContext* maestro) { maestro_context_ = maestro; } + /* For the parallel execution */ // FIXME killme + static simgrid::xbt::Parmap* parmap_; + static std::vector workers_context_; + static std::atomic threads_working_; + static thread_local uintptr_t worker_id_; + +protected: + void* stack_ = nullptr; /* the thread stack */ + private: - static unsigned long process_index_; static SwappedContext* maestro_context_; + /* For sequential and parallel run_all() */ + SwappedContextFactory* factory_; }; } // namespace context