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_activity_t);
21 typedef void (*simix_copy_data_func_t)(smx_activity_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 struct s_smx_simcall {
50 union u_smx_scalar args[11];
51 union u_smx_scalar result;
54 #define SIMCALL_SET_MC_VALUE(simcall, value) ((simcall)->mc_value = (value))
55 #define SIMCALL_GET_MC_VALUE(simcall) ((simcall)->mc_value)
57 /******************************** General *************************************/
59 XBT_PRIVATE void SIMIX_simcall_answer(smx_simcall_t simcall);
60 XBT_PRIVATE void SIMIX_simcall_handle(smx_simcall_t simcall, int value);
61 XBT_PRIVATE void SIMIX_simcall_exit(smx_activity_t synchro);
62 XBT_PRIVATE const char *SIMIX_simcall_name(e_smx_simcall_t kind);
63 XBT_PRIVATE void SIMIX_run_kernel(std::function<void()> const* code);
64 XBT_PRIVATE void SIMIX_run_blocking(std::function<void()> const* code);
75 constexpr bool operator==(type) const { return true; }
77 constexpr bool operator==(type<U>) const { return false; }
78 constexpr bool operator!=(type) const { return false; }
80 constexpr bool operator!=(type<U>) const { return true; }
83 template<typename T> struct marshal_t {};
84 #define SIMIX_MARSHAL(T, field) \
85 inline void marshal(type<T>, u_smx_scalar& simcall, T value) \
87 simcall.field = value; \
89 inline T unmarshal(type<T>, u_smx_scalar const& simcall) \
91 return simcall.field; \
94 SIMIX_MARSHAL(char, c);
95 SIMIX_MARSHAL(short, s);
96 SIMIX_MARSHAL(int, i);
97 SIMIX_MARSHAL(long, l);
98 SIMIX_MARSHAL(unsigned char, uc);
99 SIMIX_MARSHAL(unsigned short, us);
100 SIMIX_MARSHAL(unsigned int, ui);
101 SIMIX_MARSHAL(unsigned long, ul);
102 SIMIX_MARSHAL(unsigned long long, ull);
103 SIMIX_MARSHAL(long long, ll);
104 SIMIX_MARSHAL(float, d);
105 SIMIX_MARSHAL(double, d);
106 SIMIX_MARSHAL(FPtr, fp);
109 void unmarshal(type<void>, u_smx_scalar const& simcall) {}
111 template<class T> inline
112 void marshal(type<T*>, u_smx_scalar& simcall, T* value)
114 simcall.dp = (void*) value;
116 template<class T> inline
117 T* unmarshal(type<T*>, u_smx_scalar const& simcall)
119 return static_cast<T*>(simcall.dp);
122 template<class R, class... T> inline
123 void marshal(type<R(*)(T...)>, u_smx_scalar& simcall, R(*value)(T...))
125 simcall.fp = (FPtr) value;
127 template<class R, class... T> inline
128 auto unmarshal(type<R(*)(T...)>, u_smx_scalar simcall) -> R(*)(T...)
130 return (R(*)(T...)) simcall.fp;
133 template<class T> inline
134 void marshal(u_smx_scalar& simcall, T const& value)
136 return marshal(type<T>(), simcall, value);
138 template<class T> inline
139 typename std::remove_reference<T>::type unmarshal(u_smx_scalar& simcall)
141 return unmarshal(type<T>(), simcall);
144 template<std::size_t I>
145 inline void marshalArgs(smx_simcall_t simcall) {}
147 template<std::size_t I, class A>
148 inline void marshalArgs(smx_simcall_t simcall, A const& a)
150 marshal(simcall->args[I], a);
153 template<std::size_t I, class A, class... B>
154 inline void marshalArgs(smx_simcall_t simcall, A const& a, B const&... b)
156 marshal(simcall->args[I], a);
157 marshalArgs<I+1>(simcall, b...);
160 /** Initialize the simcall */
161 template<class... A> inline
162 void marshal(smx_simcall_t simcall, e_smx_simcall_t call, A const&... a)
164 simcall->call = call;
165 memset(&simcall->result, 0, sizeof(simcall->result));
166 memset(simcall->args, 0, sizeof(simcall->args));
167 marshalArgs<0>(simcall, a...);
175 #include "popping_accessors.h"