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
17 #include <xbt/function_types.h>
18 #include <simgrid/simix.h>
26 class ContextFactory {
31 ContextFactory(std::string name) : name_(std::move(name)) {}
32 virtual ~ContextFactory();
33 virtual Context* create_context(std::function<void()> code,
34 void_pfn_smxprocess_t cleanup, smx_process_t process) = 0;
35 virtual void run_all() = 0;
36 virtual Context* self();
37 std::string const& name() const
42 void declare_context(void* T, std::size_t size);
44 template<class T, class... Args>
45 T* new_context(Args&&... args)
47 T* context = new T(std::forward<Args>(args)...);
48 this->declare_context(context, sizeof(T));
55 std::function<void()> code_;
56 void_pfn_smxprocess_t cleanup_func_ = nullptr;
57 smx_process_t process_ = nullptr;
61 Context(std::function<void()> code,
62 void_pfn_smxprocess_t cleanup_func,
63 smx_process_t process);
72 smx_process_t process()
74 return this->process_;
76 void set_cleanup(void_pfn_smxprocess_t cleanup)
78 cleanup_func_ = cleanup;
84 virtual void suspend() = 0;