Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove SIMIX_host_get_current_power_peak() and SIMIX_host_get_power_peak_at()
[simgrid.git] / src / simix / smx_private.hpp
1 /* Copyright (c) 2007-2010, 2012-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #ifndef SIMGRID_SIMIX_PRIVATE_HPP
8 #define SIMGRID_SIMIX_PRIVATE_HPP
9
10 #include <simgrid/simix.hpp>
11 #include "smx_private.h"
12 #include "src/simix/popping_private.h"
13
14 /**
15  * \brief destroy a context
16  * \param context the context to destroy
17  * Argument must be stopped first -- runs in maestro context
18  */
19 static XBT_INLINE void SIMIX_context_free(smx_context_t context)
20 {
21   delete context;
22 }
23
24 /**
25  * \brief stops the execution of a context
26  * \param context to stop
27  */
28 static XBT_INLINE void SIMIX_context_stop(smx_context_t context)
29 {
30   context->stop();
31 }
32
33 /**
34  \brief suspends a context and return the control back to the one which
35         scheduled it
36  \param context the context to be suspended (it must be the running one)
37  */
38 static XBT_INLINE void SIMIX_context_suspend(smx_context_t context)
39 {
40   context->suspend();
41 }
42
43 /**
44  \brief Executes all the processes to run (in parallel if possible).
45  */
46 static XBT_INLINE void SIMIX_context_runall(void)
47 {
48   if (!xbt_dynar_is_empty(simix_global->process_to_run))
49     simix_global->context_factory->run_all();
50 }
51
52 /**
53  \brief returns the current running context
54  */
55 static XBT_INLINE smx_context_t SIMIX_context_self(void)
56 {
57   if (simix_global && simix_global->context_factory)
58     return simix_global->context_factory->self();
59   else
60     return nullptr;
61 }
62
63 /**
64  \brief returns the SIMIX process associated to a context
65  \param context The context
66  \return The SIMIX process
67  */
68 static XBT_INLINE smx_process_t SIMIX_context_get_process(smx_context_t context)
69 {
70   return context->process();
71 }
72
73 namespace simgrid {
74 namespace simix {
75
76 XBT_PRIVATE ContextFactory* thread_factory();
77 XBT_PRIVATE ContextFactory* sysv_factory();
78 XBT_PRIVATE ContextFactory* raw_factory();
79 XBT_PRIVATE ContextFactory* boost_factory();
80
81 template<class R, class... Args> inline
82 R simcall(e_smx_simcall_t call, Args&&... args)
83 {
84   smx_process_t self = SIMIX_process_self();
85   marshal(&self->simcall, call, std::forward<Args>(args)...);
86   simcall_call(self);
87   return unmarshal<R>(self->simcall.result);
88 }
89
90 }
91 }
92
93 #endif