1 /* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved. */
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. */
6 #ifndef SG_POPPING_PRIVATE_H
7 #define SG_POPPING_PRIVATE_H
10 #include <simgrid/simix.h>
14 /********************************* Simcalls *********************************/
15 XBT_PUBLIC_DATA(const char*) simcall_names[]; /* Name of each simcall */
17 #include "popping_enum.h" /* Definition of e_smx_simcall_t, with one value per simcall */
19 typedef int (*simix_match_func_t)(void *, void *, smx_activity_t);
20 typedef void (*simix_copy_data_func_t)(smx_activity_t, void*, size_t);
21 typedef void (*simix_clean_func_t)(void *);
22 typedef void (*FPtr)(void); // Hide the ugliness
24 /* Pack all possible scalar types in an union */
35 unsigned long long ull;
42 * \brief Represents a simcall to the kernel.
44 struct s_smx_simcall {
49 union u_smx_scalar args[11];
50 union u_smx_scalar result;
53 #define SIMCALL_SET_MC_VALUE(simcall, value) ((simcall)->mc_value = (value))
54 #define SIMCALL_GET_MC_VALUE(simcall) ((simcall)->mc_value)
56 /******************************** General *************************************/
58 XBT_PRIVATE void SIMIX_simcall_answer(smx_simcall_t simcall);
59 XBT_PRIVATE void SIMIX_simcall_handle(smx_simcall_t simcall, int value);
60 XBT_PRIVATE void SIMIX_simcall_exit(smx_activity_t synchro);
61 XBT_PRIVATE const char *SIMIX_simcall_name(e_smx_simcall_t kind);
62 XBT_PRIVATE void SIMIX_run_kernel(std::function<void()> const* code);
63 XBT_PRIVATE void SIMIX_run_blocking(std::function<void()> const* code);
74 constexpr bool operator==(type) const { return true; }
76 constexpr bool operator==(type<U>) const { return false; }
77 constexpr bool operator!=(type) const { return false; }
79 constexpr bool operator!=(type<U>) const { return true; }
82 template<typename T> struct marshal_t {};
83 #define SIMIX_MARSHAL(T, field) \
84 inline void marshal(type<T>, u_smx_scalar& simcall, T value) \
86 simcall.field = value; \
88 inline T unmarshal(type<T>, u_smx_scalar const& simcall) \
90 return simcall.field; \
93 SIMIX_MARSHAL(char, c);
94 SIMIX_MARSHAL(short, s);
95 SIMIX_MARSHAL(int, i);
96 SIMIX_MARSHAL(long, l);
97 SIMIX_MARSHAL(unsigned char, uc);
98 SIMIX_MARSHAL(unsigned short, us);
99 SIMIX_MARSHAL(unsigned int, ui);
100 SIMIX_MARSHAL(unsigned long, ul);
101 SIMIX_MARSHAL(unsigned long long, ull);
102 SIMIX_MARSHAL(long long, ll);
103 SIMIX_MARSHAL(float, d);
104 SIMIX_MARSHAL(double, d);
105 SIMIX_MARSHAL(FPtr, fp);
108 void unmarshal(type<void>, u_smx_scalar const& simcall) {}
110 template<class T> inline
111 void marshal(type<T*>, u_smx_scalar& simcall, T* value)
113 simcall.dp = (void*) value;
115 template<class T> inline
116 T* unmarshal(type<T*>, u_smx_scalar const& simcall)
118 return static_cast<T*>(simcall.dp);
121 template<class R, class... T> inline
122 void marshal(type<R(*)(T...)>, u_smx_scalar& simcall, R(*value)(T...))
124 simcall.fp = (FPtr) value;
126 template<class R, class... T> inline
127 auto unmarshal(type<R(*)(T...)>, u_smx_scalar simcall) -> R(*)(T...)
129 return (R(*)(T...)) simcall.fp;
132 template<class T> inline
133 void marshal(u_smx_scalar& simcall, T const& value)
135 return marshal(type<T>(), simcall, value);
137 template<class T> inline
138 typename std::remove_reference<T>::type unmarshal(u_smx_scalar& simcall)
140 return unmarshal(type<T>(), simcall);
143 template<std::size_t I>
144 inline void marshalArgs(smx_simcall_t simcall) {}
146 template<std::size_t I, class A>
147 inline void marshalArgs(smx_simcall_t simcall, A const& a)
149 marshal(simcall->args[I], a);
152 template<std::size_t I, class A, class... B>
153 inline void marshalArgs(smx_simcall_t simcall, A const& a, B const&... b)
155 marshal(simcall->args[I], a);
156 marshalArgs<I+1>(simcall, b...);
159 /** Initialize the simcall */
160 template<class... A> inline
161 void marshal(smx_simcall_t simcall, e_smx_simcall_t call, A const&... a)
163 simcall->call = call;
164 memset(&simcall->result, 0, sizeof(simcall->result));
165 memset(simcall->args, 0, sizeof(simcall->args));
166 marshalArgs<0>(simcall, a...);
174 #include "popping_accessors.h"