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 _POPPING_PRIVATE_H
8 #define _POPPING_PRIVATE_H
11 #include <simgrid/simix.h>
15 /********************************* Simcalls *********************************/
16 XBT_PUBLIC_DATA(const char*) simcall_names[]; /* Name of each simcall */
18 #include "popping_enum.h" /* Definition of e_smx_simcall_t, with one value per simcall */
20 typedef int (*simix_match_func_t)(void *, void *, smx_synchro_t);
21 typedef void (*simix_copy_data_func_t)(smx_synchro_t, void*, size_t);
22 typedef void (*simix_clean_func_t)(void *);
23 typedef void (*FPtr)(void); // Hide the ugliness
25 /* Pack all possible scalar types in an union */
36 unsigned long long ull;
43 * \brief Represents a simcall to the kernel.
45 typedef struct s_smx_simcall {
49 union u_smx_scalar args[11];
50 union u_smx_scalar result;
51 } s_smx_simcall_t, *smx_simcall_t;
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);
59 XBT_PRIVATE void SIMIX_simcall_handle(smx_simcall_t, int);
60 XBT_PRIVATE void SIMIX_simcall_exit(smx_synchro_t);
61 XBT_PRIVATE const char *SIMIX_simcall_name(e_smx_simcall_t kind);
62 XBT_PRIVATE void SIMIX_run_kernel(void* code);
73 constexpr bool operator==(type) const { return true; }
75 constexpr bool operator==(type<U>) const { return false; }
76 constexpr bool operator!=(type) const { return false; }
78 constexpr bool operator!=(type<U>) const { return true; }
81 template<typename T> struct marshal_t {};
82 #define SIMIX_MARSHAL(T, field) \
83 inline void marshal(type<T>, u_smx_scalar& simcall, T value) \
85 simcall.field = value; \
87 inline T unmarshal(type<T>, u_smx_scalar const& simcall) \
89 return simcall.field; \
92 SIMIX_MARSHAL(char, c);
93 SIMIX_MARSHAL(short, s);
94 SIMIX_MARSHAL(int, i);
95 SIMIX_MARSHAL(long, l);
96 SIMIX_MARSHAL(unsigned char, uc);
97 SIMIX_MARSHAL(unsigned short, us);
98 SIMIX_MARSHAL(unsigned int, ui);
99 SIMIX_MARSHAL(unsigned long, ul);
100 SIMIX_MARSHAL(unsigned long long, ull);
101 SIMIX_MARSHAL(long long, ll);
102 SIMIX_MARSHAL(float, d);
103 SIMIX_MARSHAL(double, d);
104 SIMIX_MARSHAL(FPtr, fp);
107 void unmarshal(type<void>, u_smx_scalar const& simcall) {}
109 template<class T> inline
110 void marshal(type<T*>, u_smx_scalar& simcall, T* value)
112 simcall.dp = (void*) value;
114 template<class T> inline
115 T* unmarshal(type<T*>, u_smx_scalar const& simcall)
117 return static_cast<T*>(simcall.dp);
120 template<class R, class... T> inline
121 void marshal(type<R(*)(T...)>, u_smx_scalar& simcall, R(*value)(T...))
123 simcall.fp = (FPtr) value;
125 template<class R, class... T> inline
126 auto unmarshal(type<R(*)(T...)>, u_smx_scalar simcall) -> R(*)(T...)
128 return (R(*)(T...)) simcall.fp;
131 template<class T> inline
132 void marshal(u_smx_scalar& simcall, T const& value)
134 return marshal(type<T>(), simcall, value);
136 template<class T> inline
137 typename std::remove_reference<T>::type unmarshal(u_smx_scalar& simcall)
139 return unmarshal(type<T>(), simcall);
142 template<std::size_t I>
143 inline void marshalArgs(smx_simcall_t simcall) {}
145 template<std::size_t I, class A>
146 inline void marshalArgs(smx_simcall_t simcall, A const& a)
148 marshal(simcall->args[I], a);
151 template<std::size_t I, class A, class... B>
152 inline void marshalArgs(smx_simcall_t simcall, A const& a, B const&... b)
154 marshal(simcall->args[I], a);
155 marshalArgs<I+1>(simcall, b...);
158 /** Initialize the simcall */
159 template<class... A> inline
160 void marshal(smx_simcall_t simcall, e_smx_simcall_t call, A const&... a)
162 simcall->call = call;
163 memset(&simcall->result, 0, sizeof(simcall->result));
164 memset(simcall->args, 0, sizeof(simcall->args));
165 marshalArgs<0>(simcall, a...);
173 #include "popping_accessors.h"