1 /* Copyright (c) 2007-2010, 2012-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 #ifndef SIMGRID_SIMIX_HPP
8 #define SIMGRID_SIMIX_HPP
14 #include <xbt/function_types.h>
15 #include <simgrid/simix.h>
23 class ContextFactory {
28 ContextFactory(std::string name) : name_(std::move(name)) {}
29 virtual ~ContextFactory();
30 virtual Context* create_context(std::function<void()> code,
31 void_pfn_smxprocess_t cleanup, smx_process_t process) = 0;
32 virtual void run_all() = 0;
33 virtual Context* self();
34 std::string const& name() const
39 void declare_context(void* T, std::size_t size);
41 template<class T, class... Args>
42 T* new_context(Args&&... args)
44 T* context = new T(std::forward<Args>(args)...);
45 this->declare_context(context, sizeof(T));
52 std::function<void()> code_;
53 void_pfn_smxprocess_t cleanup_func_ = nullptr;
54 smx_process_t process_ = nullptr;
58 Context(std::function<void()> code,
59 void_pfn_smxprocess_t cleanup_func,
60 smx_process_t process);
69 smx_process_t process()
71 return this->process_;
73 void set_cleanup(void_pfn_smxprocess_t cleanup)
75 cleanup_func_ = cleanup;
81 virtual void suspend() = 0;