Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Remove the SNAPSHOT and COMPARE_SNAPSHOTS MC simcalls
[simgrid.git] / src / simix / popping_private.h
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 _POPPING_PRIVATE_H
8 #define _POPPING_PRIVATE_H
9
10 #include <xbt/base.h>
11 #include <simgrid/simix.h>
12
13 SG_BEGIN_DECL()
14
15 /********************************* Simcalls *********************************/
16 XBT_PUBLIC_DATA(const char*) simcall_names[]; /* Name of each simcall */
17
18 #include "popping_enum.h" /* Definition of e_smx_simcall_t, with one value per simcall */
19 #include "src/mc/mc_forward.h" /* Definition of mc_snapshot_t, used by one simcall */
20
21 typedef int (*simix_match_func_t)(void *, void *, smx_synchro_t);
22 typedef void (*simix_copy_data_func_t)(smx_synchro_t, void*, size_t);
23 typedef void (*simix_clean_func_t)(void *);
24 typedef void (*FPtr)(void); // Hide the ugliness
25
26 /* Pack all possible scalar types in an union */
27 union u_smx_scalar {
28   char            c;
29   const char*     cc;
30   short           s;
31   int             i;
32   long            l;
33   unsigned char   uc;
34   unsigned short  us;
35   unsigned int    ui;
36   unsigned long   ul;
37   float           f;
38   double          d;
39   size_t          sz;
40   sg_size_t       sgsz;
41   sg_offset_t     sgoff;
42   void*           dp;
43   FPtr            fp;
44   const void*     cp;
45 };
46
47 /**
48  * \brief Represents a simcall to the kernel.
49  */
50 typedef struct s_smx_simcall {
51   e_smx_simcall_t call;
52   smx_process_t issuer;
53   int mc_value;
54   union u_smx_scalar args[11];
55   union u_smx_scalar result;
56 } s_smx_simcall_t, *smx_simcall_t;
57
58 #define SIMCALL_SET_MC_VALUE(simcall, value) ((simcall)->mc_value = (value))
59 #define SIMCALL_GET_MC_VALUE(simcall) ((simcall)->mc_value)
60
61 #include "popping_accessors.h"
62
63 /******************************** General *************************************/
64
65 XBT_PRIVATE void SIMIX_simcall_answer(smx_simcall_t);
66 XBT_PRIVATE void SIMIX_simcall_handle(smx_simcall_t, int);
67 XBT_PRIVATE void SIMIX_simcall_exit(smx_synchro_t);
68 XBT_PRIVATE const char *SIMIX_simcall_name(e_smx_simcall_t kind);
69 XBT_PRIVATE void SIMIX_run_kernel(void* code);
70
71 SG_END_DECL()
72
73 #ifdef __cplusplus
74
75 namespace simgrid {
76 namespace simix {
77
78 template<typename T> struct marshal_t {};
79 #define SIMIX_MARSHAL(T, field) \
80   template<> struct marshal_t<T> { \
81     static void marshal(u_smx_scalar& simcall, T value) \
82     { \
83       simcall.field = value; \
84     } \
85     static T unmarshal(u_smx_scalar const& simcall) \
86     { \
87       return simcall.field; \
88     } \
89   };
90
91 SIMIX_MARSHAL(char, c);
92 SIMIX_MARSHAL(short, s);
93 SIMIX_MARSHAL(int, i);
94 SIMIX_MARSHAL(long, l);
95 SIMIX_MARSHAL(unsigned char, uc);
96 SIMIX_MARSHAL(unsigned short, us);
97 SIMIX_MARSHAL(unsigned int, ui);
98 SIMIX_MARSHAL(unsigned long, ul);
99 SIMIX_MARSHAL(float, f);
100 SIMIX_MARSHAL(double, d);
101 SIMIX_MARSHAL(FPtr, fp);
102
103 template<typename T> struct marshal_t<T*> {
104   static void marshal(u_smx_scalar& simcall, T* value)
105   {
106     simcall.dp = value;
107   }
108   static T* unmarshal(u_smx_scalar const& simcall)
109   {
110     return simcall.dp;
111   }
112 };
113
114 template<> struct marshal_t<void> {
115   static void unmarshal(u_smx_scalar const& simcall) {}
116 };
117
118 template<class T> inline
119 void marshal(u_smx_scalar& simcall, T const& value)
120 {
121   marshal_t<T>::marshal(simcall, value);
122 }
123
124 template<class T> inline
125 T unmarshal(u_smx_scalar const& simcall)
126 {
127   return marshal_t<T>::unmarshal(simcall);
128 }
129
130 template<class A> inline
131 void marshal(smx_simcall_t simcall, e_smx_simcall_t call, A&& a)
132 {
133   simcall->call = call;
134   memset(&simcall->result, 0, sizeof(simcall->result));
135   marshal(simcall->args[0], std::forward<A>(a));
136 }
137
138 template<class A, class B> inline
139 void marshal(smx_simcall_t simcall, e_smx_simcall_t call, A&& a, B&& b)
140 {
141   simcall->call = call;
142   memset(&simcall->result, 0, sizeof(simcall->result));
143   marshal(simcall->args[0], std::forward<A>(a));
144   marshal(simcall->args[1], std::forward<B>(b));
145 }
146
147 template<class A, class B, class C> inline
148 void marshal(smx_simcall_t simcall, e_smx_simcall_t call, A&& a, B&& b, C&& c)
149 {
150   simcall->call = call;
151   memset(&simcall->result, 0, sizeof(simcall->result));
152   marshal(simcall->args[0], std::forward<A>(a));
153   marshal(simcall->args[1], std::forward<B>(b));
154   marshal(simcall->args[2], std::forward<C>(c));
155 }
156
157 template<class A, class B, class C, class D> inline
158 void marshal(smx_simcall_t simcall, e_smx_simcall_t call, A&& a, B&& b, C&& c, D&& d)
159 {
160   simcall->call = call;
161   memset(&simcall->result, 0, sizeof(simcall->result));
162   marshal(simcall->args[0], std::forward<A>(a));
163   marshal(simcall->args[1], std::forward<B>(b));
164   marshal(simcall->args[2], std::forward<C>(c));
165   marshal(simcall->args[3], std::forward<D>(d));
166 }
167
168 template<class A, class B, class C, class D, class E> inline
169 void marshal(smx_simcall_t simcall, e_smx_simcall_t call, A&& a, B&& b, C&& c, D&& d, E&& e)
170 {
171   simcall->call = call;
172   memset(&simcall->result, 0, sizeof(simcall->result));
173   marshal(simcall->args[0], std::forward<A>(a));
174   marshal(simcall->args[1], std::forward<B>(b));
175   marshal(simcall->args[2], std::forward<C>(c));
176   marshal(simcall->args[3], std::forward<D>(d));
177   marshal(simcall->args[4], std::forward<E>(e));
178 }
179
180 template<class A, class B, class C, class D, class E, class F> inline
181 void marshal(smx_simcall_t simcall, e_smx_simcall_t call,
182   A&& a, B&& b, C&& c, D&& d, E&& e, F&& f)
183 {
184   simcall->call = call;
185   memset(&simcall->result, 0, sizeof(simcall->result));
186   marshal(simcall->args[0], std::forward<A>(a));
187   marshal(simcall->args[1], std::forward<B>(b));
188   marshal(simcall->args[2], std::forward<C>(c));
189   marshal(simcall->args[3], std::forward<D>(d));
190   marshal(simcall->args[4], std::forward<E>(e));
191   marshal(simcall->args[5], std::forward<F>(f));
192 }
193
194 template<class A, class B, class C, class D, class E, class F, class G> inline
195 void marshal(smx_simcall_t simcall, e_smx_simcall_t call,
196   A&& a, B&& b, C&& c, D&& d, E&& e, F&& f, G&& g)
197 {
198   simcall->call = call;
199   memset(&simcall->result, 0, sizeof(simcall->result));
200   marshal(simcall->args[0], std::forward<A>(a));
201   marshal(simcall->args[1], std::forward<B>(b));
202   marshal(simcall->args[2], std::forward<C>(c));
203   marshal(simcall->args[3], std::forward<D>(d));
204   marshal(simcall->args[4], std::forward<E>(e));
205   marshal(simcall->args[5], std::forward<F>(f));
206   marshal(simcall->args[6], std::forward<G>(g));
207 }
208
209 template<class A, class B, class C,
210           class D, class E, class F, class G, class H> inline
211 void marshal(smx_simcall_t simcall, e_smx_simcall_t call,
212   A&& a, B&& b, C&& c, D&& d, E&& e, F&& f, G&& g, H&& h)
213 {
214   simcall->call = call;
215   memset(&simcall->result, 0, sizeof(simcall->result));
216   marshal(simcall->args[0], std::forward<A>(a));
217   marshal(simcall->args[1], std::forward<B>(b));
218   marshal(simcall->args[2], std::forward<C>(c));
219   marshal(simcall->args[3], std::forward<D>(d));
220   marshal(simcall->args[4], std::forward<E>(e));
221   marshal(simcall->args[5], std::forward<F>(f));
222   marshal(simcall->args[6], std::forward<G>(g));
223   marshal(simcall->args[7], std::forward<H>(h));
224 }
225
226 template<class A, class B, class C,
227           class D, class E, class F,
228           class G, class H, class I> inline
229 void marshal(smx_simcall_t simcall, e_smx_simcall_t call,
230   A&& a, B&& b, C&& c, D&& d, E&& e, F&& f, G&& g, H&& h, I&& i)
231 {
232   simcall->call = call;
233   memset(&simcall->result, 0, sizeof(simcall->result));
234   marshal(simcall->args[0], std::forward<A>(a));
235   marshal(simcall->args[1], std::forward<B>(b));
236   marshal(simcall->args[2], std::forward<C>(c));
237   marshal(simcall->args[3], std::forward<D>(d));
238   marshal(simcall->args[4], std::forward<E>(e));
239   marshal(simcall->args[5], std::forward<F>(f));
240   marshal(simcall->args[6], std::forward<G>(g));
241   marshal(simcall->args[7], std::forward<H>(h));
242   marshal(simcall->args[8], std::forward<I>(i));
243 }
244
245 }
246 }
247
248 #endif
249
250 #endif