Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix debug message in simix
[simgrid.git] / src / simix / smx_smurf_private.h
1 /* Copyright (c) 2007, 2008, 2009, 2010. 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 _SIMIX_SMURF_PRIVATE_H
8 #define _SIMIX_SMURF_PRIVATE_H
9
10 /********************************* Simcalls *********************************/
11
12 /* we want to build the e_smx_simcall_t enumeration, the table of the
13  * corresponding simcalls string names, and the simcall handlers table
14  * automatically, using macros.
15  * To add a new simcall follow the following syntax:
16  *
17  * SIMCALL_ENUM_ELEMENT(<simcall_enumeration_id>, <simcall_handler_function>)
18  *
19  * */
20
21 /****************************
22  * SIMCALL GENERATING MACRO *
23  ****************************
24  *
25  * action(ENUM_NAME, func_name, result_type, params…) 
26  *
27  **/
28
29 /*
30  * Some macro machinery to get a MAP over the arguments of a variadic macro.
31  * It uses a FOLD to apply a macro to every argument, and because there is
32  * no recursion in the C preprocessor we must create a new macro for every
33  * depth of FOLD's recursion.
34  */
35
36 /* FOLD macro */
37 #define FE_0(WHAT, X, ...)
38 #define FE_1(I, WHAT, X) WHAT(I, X)
39 #define FE_2(I, WHAT, X, ...) WHAT(I, X), FE_1(I+1, WHAT, __VA_ARGS__)
40 #define FE_3(I, WHAT, X, ...) WHAT(I, X), FE_2(I+1, WHAT, __VA_ARGS__)
41 #define FE_4(I, WHAT, X, ...) WHAT(I, X), FE_3(I+1, WHAT, __VA_ARGS__)
42 #define FE_5(I, WHAT, X, ...) WHAT(I, X), FE_4(I+1, WHAT, __VA_ARGS__)
43 #define FE_6(I, WHAT, X, ...) WHAT(I, X), FE_5(I+1, WHAT, __VA_ARGS__)
44 #define FE_7(I, WHAT, X, ...) WHAT(I, X), FE_6(I+1, WHAT, __VA_ARGS__)
45 #define FE_8(I, WHAT, X, ...) WHAT(I, X), FE_7(I+1, WHAT, __VA_ARGS__)
46 #define FE_9(I, WHAT, X, ...) WHAT(I, X), FE_8(I+1, WHAT, __VA_ARGS__)
47 #define FE_10(I, WHAT, X, ...) WHAT(I, X), FE_9(I+1, WHAT, __VA_ARGS__)
48
49 /* NOTE: add as many FE_n as needed (maximum number of simcall arguments )*/
50
51 /* Make a MAP macro usgin FOLD (will apply 'action' to the arguments.
52  * GET_MACRO is a smart hack that counts the number of arguments passed to
53  * the variadic macro, and it is used to invoke the right FOLD depth.
54  */
55 #define GET_MACRO(_0,_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
56 #define MAP(action, ...) \
57   GET_MACRO(, ##__VA_ARGS__, FE_10,FE_9,FE_8,FE_7,FE_6,FE_5,FE_4,FE_3,FE_2,FE_1, FE_0) (0, action, __VA_ARGS__)
58
59 /* MAP with default arguments */
60 #define APPLY_MAP(WHAT, I, X, ...) WHAT(I, __VA_ARGS__, X)
61 #define FE_DA_0(I, WHAT, args, X, ...)
62 #define FE_DA_1(I, WHAT, args, X, ...) APPLY_MAP(WHAT, I, X, args)
63 #define FE_DA_2(I, WHAT, args, X, ...) APPLY_MAP(WHAT, I, X, args) FE_DA_1(I+1, WHAT, args, __VA_ARGS__)
64 #define FE_DA_3(I, WHAT, args, X, ...) APPLY_MAP(WHAT, I, X, args) FE_DA_2(I+1, WHAT, args, __VA_ARGS__)
65 #define FE_DA_4(I, WHAT, args, X, ...) APPLY_MAP(WHAT, I, X, args) FE_DA_3(I+1, WHAT, args, __VA_ARGS__)
66 #define FE_DA_5(I, WHAT, args, X, ...) APPLY_MAP(WHAT, I, X, args) FE_DA_4(I+1, WHAT, args, __VA_ARGS__)
67 #define FE_DA_6(I, WHAT, args, X, ...) APPLY_MAP(WHAT, I, X, args) FE_DA_5(I+1, WHAT, args, __VA_ARGS__)
68 #define FE_DA_7(I, WHAT, args, X, ...) APPLY_MAP(WHAT, I, X, args) FE_DA_6(I+1, WHAT, args, __VA_ARGS__)
69 #define FE_DA_8(I, WHAT, args, X, ...) APPLY_MAP(WHAT, I, X, args) FE_DA_7(I+1, WHAT, args, __VA_ARGS__)
70 #define FE_DA_9(I, WHAT, args, X, ...) APPLY_MAP(WHAT, I, X, args) FE_DA_8(I+1, WHAT, args, __VA_ARGS__)
71 #define FE_DA_10(I, WHAT, args, X, ...) APPLY_MAP(WHAT, I, X, args) FE_DA_9(I+1, WHAT, args, __VA_ARGS__)
72
73 #define MAP_WITH_DEFAULT_ARGS(action, args, ...) \
74   GET_MACRO(, ##__VA_ARGS__, FE_DA_10,FE_DA_9,FE_DA_8,FE_DA_7,FE_DA_6,FE_DA_5,FE_DA_4,FE_DA_3,FE_DA_2,FE_DA_1, FE_DA_0) (0, action, args, __VA_ARGS__)
75
76 /*
77  * Define scalar type wrappers to ease the use of simcalls.
78  * These are used to wrap the arguments in SIMIX_simcall macro.
79  */
80 #define TCHAR(n) (n, char, c)
81 #define TSTRING(n) (n, const char*, cc)
82 #define TSHORT(n) (n, short, s)
83 #define TINT(n) (n, int, i)
84 #define TLONG(n) (n, long, l)
85 #define TUCHAR(n) (n, unsigned char, uc)
86 #define TUSHORT(n) (n, unsigned short, us)
87 #define TUINT(n) (n, unsigned int, ui)
88 #define TULONG(n) (n, unsigned long, ul)
89 #define TFLOAT(n) (n, float, f)
90 #define TDOUBLE(n) (n, double, d)
91 #define TPTR(n) (n, void*, p)
92 #define TCPTR(n) (n, const void*, cp)
93 #define TSIZE(n) (n, size_t, si)
94 #define TVOID(n) (n, void)
95 #define TSPEC(n,t) (n, t, p)
96
97 /* use comma or nothing to separate elements*/
98 #define SIMCALL_SEP_COMMA ,
99 #define SIMCALL_SEP_NOTHING
100
101 /* get the name of the parameter */
102 #define SIMCALL_NAME_(name, type, field) name
103 #define SIMCALL_NAME(i, v) SIMCALL_NAME_ v
104
105 /* get the %s format code of the parameter */
106 #define SIMCALL_FORMAT_(name, type, field) %field
107 #define SIMCALL_FORMAT(i, v) SIMCALL_FORMAT_ v
108
109 /* get the field of the parameter */
110 #define SIMCALL_FIELD_(name, type, field) field
111 #define SIMCALL_FIELD(i, v) SIMCALL_FIELD_ v
112
113 /* get the parameter declaration */
114 #define SIMCALL_ARG_(name, type, field) type name
115 #define SIMCALL_ARG(i, v) SIMCALL_ARG_ v
116
117 /* get the parameter initialisation field */
118 #define SIMCALL_INIT_FIELD_(name, type, field) {.field = name}
119 #define SIMCALL_INIT_FIELD(i, v) SIMCALL_INIT_FIELD_ v
120
121 /* get the case of the parameter */
122 #define SIMCALL_CASE_PARAM_(name, type, field) field
123 #define SIMCALL_CASE_PARAM(i, v) simcall->args[i].SIMCALL_CASE_PARAM_ v
124
125 /* generate some code for SIMCALL_CASE if the simcall has an answer */
126 #define MAYBE2(_0, _1, func, ...) func
127
128 #define SIMCALL_WITH_RESULT_BEGIN(name, type, field) simcall->result.field =
129 #define SIMCALL_WITHOUT_RESULT_BEGIN(name, type, field)
130 #define SIMCALL_RESULT_BEGIN_(name, type, ...)\
131         MAYBE2(,##__VA_ARGS__, SIMCALL_WITH_RESULT_BEGIN, SIMCALL_WITHOUT_RESULT_BEGIN)\
132         (name, type, __VA_ARGS__)
133 #define SIMCALL_RESULT_BEGIN(answer, res) answer(SIMCALL_RESULT_BEGIN_ res)
134
135 #define SIMCALL_RESULT_END_(name, type, ...)\
136         SIMIX_simcall_answer(simcall);
137 #define SIMCALL_RESULT_END(answer, res) answer(SIMCALL_RESULT_END_ res)
138
139 /* generate some code for BODY function */
140 #define SIMCALL_FUNC_RETURN_TYPE_(name, type, ...) type
141 #define SIMCALL_FUNC_RETURN_TYPE(res) SIMCALL_FUNC_RETURN_TYPE_ res
142
143 #define SIMCALL_WITH_FUNC_SIMCALL(name, type, field) smx_simcall_t simcall = 
144 #define SIMCALL_WITHOUT_FUNC_SIMCALL(name, type, field)
145 #define SIMCALL_FUNC_SIMCALL_(name, type, ...)\
146         MAYBE2(,##__VA_ARGS__, SIMCALL_WITH_FUNC_SIMCALL, SIMCALL_WITHOUT_FUNC_SIMCALL)\
147         (name, type, __VA_ARGS__)
148 #define SIMCALL_FUNC_SIMCALL(res) SIMCALL_FUNC_SIMCALL_ res
149
150 #define SIMCALL_WITH_FUNC_RETURN(name, type, field) return simcall->result.field;
151 #define SIMCALL_WITHOUT_FUNC_RETURN(name, type, field)
152 #define SIMCALL_FUNC_RETURN_(name, type, ...)\
153         MAYBE2(,##__VA_ARGS__, SIMCALL_WITH_FUNC_RETURN, SIMCALL_WITHOUT_FUNC_RETURN)\
154         (name, type, __VA_ARGS__)
155 #define SIMCALL_FUNC_RETURN(res) SIMCALL_FUNC_RETURN_ res
156
157
158 /* generate the simcall enumeration */
159 #define SIMCALL_ENUM(type, ...)\
160         type
161
162 /* generate the strings name from the enumeration values */
163 #define SIMCALL_STRING_TYPE(type, name, answer, res, ...)\
164         [type] = STRINGIFY(type)
165
166 /* generate strings from the enumeration values */
167 #define SIMCALL_TYPE(type, name, answer, res, ...)\
168         [type] = STRINGIFY(MAP(SIMCALL_FORMAT, __VA_ARGS__))
169
170 /* generate the simcalls functions */
171 #define SIMCALL_FUNC(type, name, answer, res, ...)\
172         inline static SIMCALL_FUNC_RETURN_TYPE(res) simcall_BODY_##name(MAP(SIMCALL_ARG, ##__VA_ARGS__)) { \
173       SIMCALL_FUNC_SIMCALL(res) __SIMIX_simcall(type, (u_smx_scalar_t[]){MAP(SIMCALL_INIT_FIELD, ##__VA_ARGS__)}); \
174       SIMCALL_FUNC_RETURN(res)\
175     }
176
177 /* generate a comma if there is an argument*/
178 #define WITHOUT_COMMA 
179 #define WITH_COMMA ,
180 #define GET_CLEAN(_0,_1,_2,_3,_4,_5,_6,_7,_8,_9,_10, NAME,...) NAME
181 #define MAYBE_COMMA(...) GET_CLEAN(,##__VA_ARGS__,WITH_COMMA,WITH_COMMA,WITH_COMMA,WITH_COMMA,WITH_COMMA,WITH_COMMA,WITH_COMMA,WITH_COMMA,WITH_COMMA,WITH_COMMA,WITHOUT_COMMA)
182
183 /* generate the simcalls cases for the SIMIX_simcall_pre function */
184 #define WITH_ANSWER(...) __VA_ARGS__
185 #define WITHOUT_ANSWER(...) 
186 #define SIMCALL_CASE(type, name, answer, res, ...)\
187     case type:\
188       SIMCALL_RESULT_BEGIN(answer, res) SIMIX_pre_ ## name(simcall MAYBE_COMMA(__VA_ARGS__) MAP(SIMCALL_CASE_PARAM, ##__VA_ARGS__));\
189       SIMCALL_RESULT_END(answer, res)\
190       break;
191
192
193 /*
194  * Generate simcall args and result getter/setter
195  */
196 #define SIMCALL_GS_SC_NAME_(n) n
197 #define SIMCALL_GS_SC_NAME(n) SIMCALL_GS_SC_NAME_ n
198 #define SIMCALL_GS_ARG_NAME(n) SIMCALL_NAME_ n
199 #define JOIN2(_0, _1) _0 ##__## _1
200 #define JOIN3(_0, _1, _2) JOIN2(_0 ##__## _1, _2)
201 #define JOIN4(_0, _1, _2, _3) JOIN3(_0 ##_## _1, _2, _3)
202 #define SIMCALL_GS_FUNC(scname, setget, vname) \
203    JOIN4(simcall, scname, setget, vname)
204
205 /* generate the simcalls args getter/setter */
206 #define SIMCALL_ARG_GETSET_(i, name, v) \
207   static inline SIMCALL_FUNC_RETURN_TYPE(v) SIMCALL_GS_FUNC(SIMCALL_GS_SC_NAME(name), get, SIMCALL_GS_ARG_NAME(v))(smx_simcall_t simcall){\
208     return simcall->args[i].SIMCALL_FIELD_ v ;\
209   }\
210   static inline void SIMCALL_GS_FUNC(SIMCALL_GS_SC_NAME(name), set, SIMCALL_GS_ARG_NAME(v))(smx_simcall_t simcall, SIMCALL_ARG_ v){\
211     simcall->args[i].SIMCALL_FIELD_ v = SIMCALL_NAME_ v ;\
212   }
213
214 #define SIMCALL_ARG_GETSET(type, name, answer, res, ...)\
215     MAP_WITH_DEFAULT_ARGS(SIMCALL_ARG_GETSET_, (name), ##__VA_ARGS__)
216
217 /* generate the simcalls result getter/setter */
218 #define SIMCALL_WITH_RES_GETSET(name, v) \
219   static inline SIMCALL_FUNC_RETURN_TYPE(v) SIMCALL_GS_FUNC(SIMCALL_GS_SC_NAME((name)), get, SIMCALL_GS_ARG_NAME(v))(smx_simcall_t simcall){\
220     return simcall->result.SIMCALL_FIELD_ v ;\
221   }\
222   static inline void SIMCALL_GS_FUNC(SIMCALL_GS_SC_NAME((name)), set, SIMCALL_GS_ARG_NAME(v))(smx_simcall_t simcall, SIMCALL_ARG_ v){\
223     simcall->result.SIMCALL_FIELD_ v = SIMCALL_NAME_ v ;\
224   }
225 #define SIMCALL_WITHOUT_RES_GETSET(name, v)
226 #define SIMCALL_RES_GETSET__(name, type, ...)\
227         MAYBE2(,##__VA_ARGS__, SIMCALL_WITH_RES_GETSET, SIMCALL_WITHOUT_RES_GETSET)
228 #define SIMCALL_RES_GETSET_(scname, v)\
229         SIMCALL_RES_GETSET__ v (scname, v)
230 #define SIMCALL_RES_GETSET(type, name, answer, res, ...)\
231   SIMCALL_RES_GETSET_(name, res)
232
233 /* generate the simcalls result getter/setter protos*/
234 #define SIMCALL_WITH_RES_GETSET_PROTO(name, v) \
235   inline SIMCALL_FUNC_RETURN_TYPE(v) SIMCALL_GS_FUNC(SIMCALL_GS_SC_NAME((name)), get, SIMCALL_GS_ARG_NAME(v))(smx_simcall_t simcall);\
236   inline void SIMCALL_GS_FUNC(SIMCALL_GS_SC_NAME((name)), set, SIMCALL_GS_ARG_NAME(v))(smx_simcall_t simcall, SIMCALL_ARG_ v);
237 #define SIMCALL_WITHOUT_RES_GETSET_PROTO(name, v)
238 #define SIMCALL_RES_GETSET_PROTO__(name, type, ...)\
239         MAYBE2(,##__VA_ARGS__, SIMCALL_WITH_RES_GETSET_PROTO, SIMCALL_WITHOUT_RES_GETSET_PROTO)
240 #define SIMCALL_RES_GETSET_PROTO_(scname, v)\
241         SIMCALL_RES_GETSET_PROTO__ v (scname, v)
242 #define SIMCALL_RES_GETSET_PROTO(type, name, answer, res, ...)\
243   SIMCALL_RES_GETSET_PROTO_(name, res)
244
245
246
247
248 /* stringify arguments */
249 #define STRINGIFY_(...) #__VA_ARGS__
250 #define STRINGIFY(...) STRINGIFY_(__VA_ARGS__)
251
252 /* the list of simcalls definitions */
253 #define SIMCALL_LIST1(ACTION, sep) \
254 ACTION(SIMCALL_HOST_GET_BY_NAME, host_get_by_name, WITH_ANSWER, TSPEC(result, smx_host_t), TSTRING(name)) sep \
255 ACTION(SIMCALL_HOST_GET_NAME, host_get_name, WITH_ANSWER, TSTRING(result), TSPEC(host, smx_host_t)) sep \
256 ACTION(SIMCALL_HOST_GET_PROPERTIES, host_get_properties, WITH_ANSWER, TSPEC(result, xbt_dict_t), TSPEC(host, smx_host_t)) sep \
257 ACTION(SIMCALL_HOST_GET_SPEED, host_get_speed, WITH_ANSWER, TDOUBLE(result), TSPEC(host, smx_host_t)) sep \
258 ACTION(SIMCALL_HOST_GET_AVAILABLE_SPEED, host_get_available_speed, WITH_ANSWER, TDOUBLE(result), TSPEC(host, smx_host_t)) sep \
259 ACTION(SIMCALL_HOST_GET_STATE, host_get_state, WITH_ANSWER, TINT(result), TSPEC(host, smx_host_t)) sep \
260 ACTION(SIMCALL_HOST_GET_DATA, host_get_data, WITH_ANSWER, TPTR(result), TSPEC(host, smx_host_t)) sep \
261 ACTION(SIMCALL_HOST_SET_DATA, host_set_data, WITH_ANSWER, TVOID(result), TSPEC(host, smx_host_t), TPTR(data)) sep \
262 ACTION(SIMCALL_HOST_EXECUTE, host_execute, WITH_ANSWER, TSPEC(result, smx_action_t), TSTRING(name), TSPEC(host, smx_host_t), TDOUBLE(computation_amount), TDOUBLE(priority)) sep \
263 ACTION(SIMCALL_HOST_PARALLEL_EXECUTE, host_parallel_execute, WITH_ANSWER, TSPEC(result, smx_action_t), TSTRING(name), TINT(host_nb), TSPEC(host_list, smx_host_t*), TSPEC(computation_amount, double*), TSPEC(communication_amount, double*), TDOUBLE(amount), TDOUBLE(rate)) sep \
264 ACTION(SIMCALL_HOST_EXECUTION_DESTROY, host_execution_destroy, WITH_ANSWER, TVOID(result), TSPEC(execution, smx_action_t)) sep \
265 ACTION(SIMCALL_HOST_EXECUTION_CANCEL, host_execution_cancel, WITH_ANSWER, TVOID(result), TSPEC(execution, smx_action_t)) sep \
266 ACTION(SIMCALL_HOST_EXECUTION_GET_REMAINS, host_execution_get_remains, WITH_ANSWER, TDOUBLE(result), TSPEC(execution, smx_action_t)) sep \
267 ACTION(SIMCALL_HOST_EXECUTION_GET_STATE, host_execution_get_state, WITH_ANSWER, TINT(result), TSPEC(execution, smx_action_t)) sep \
268 ACTION(SIMCALL_HOST_EXECUTION_SET_PRIORITY, host_execution_set_priority, WITH_ANSWER, TVOID(result), TSPEC(execution, smx_action_t), TDOUBLE(priority)) sep \
269 ACTION(SIMCALL_HOST_EXECUTION_WAIT, host_execution_wait, WITHOUT_ANSWER, TINT(result), TSPEC(execution, smx_action_t)) sep \
270 ACTION(SIMCALL_PROCESS_CREATE, process_create, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t*), TSTRING(name), TSPEC(code, xbt_main_func_t), TPTR(data), TSTRING(hostname), TDOUBLE(kill_time), TINT(argc), TSPEC(argv, char**), TSPEC(properties, xbt_dict_t), TINT(auto_restart)) sep \
271 ACTION(SIMCALL_PROCESS_KILL, process_kill, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t)) sep \
272 ACTION(SIMCALL_PROCESS_KILLALL, process_killall, WITH_ANSWER, TVOID(result)) sep \
273 ACTION(SIMCALL_PROCESS_CLEANUP, process_cleanup, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t)) sep \
274 ACTION(SIMCALL_PROCESS_CHANGE_HOST, process_change_host, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t), TSPEC(dest, smx_host_t)) sep \
275 ACTION(SIMCALL_PROCESS_SUSPEND, process_suspend, WITHOUT_ANSWER, TVOID(result), TSPEC(process, smx_process_t)) sep \
276 ACTION(SIMCALL_PROCESS_RESUME, process_resume, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t)) sep \
277 ACTION(SIMCALL_PROCESS_COUNT, process_count, WITH_ANSWER, TINT(result)) sep \
278 ACTION(SIMCALL_PROCESS_GET_DATA, process_get_data, WITH_ANSWER, TPTR(result), TSPEC(process, smx_process_t)) sep \
279 ACTION(SIMCALL_PROCESS_SET_DATA, process_set_data, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t), TPTR(data)) sep \
280 ACTION(SIMCALL_PROCESS_GET_HOST, process_get_host, WITH_ANSWER, TSPEC(result, smx_host_t), TSPEC(process, smx_process_t)) sep \
281 ACTION(SIMCALL_PROCESS_GET_NAME, process_get_name, WITH_ANSWER, TSTRING(result), TSPEC(process, smx_process_t)) sep \
282 ACTION(SIMCALL_PROCESS_IS_SUSPENDED, process_is_suspended, WITH_ANSWER, TINT(result), TSPEC(process, smx_process_t)) sep \
283 ACTION(SIMCALL_PROCESS_GET_PROPERTIES, process_get_properties, WITH_ANSWER, TSPEC(result, xbt_dict_t), TSPEC(process, smx_process_t)) sep \
284 ACTION(SIMCALL_PROCESS_SLEEP, process_sleep, WITHOUT_ANSWER, TINT(result), TDOUBLE(duration)) sep \
285 ACTION(SIMCALL_PROCESS_ON_EXIT, process_on_exit, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t), TSPEC(fun, int_f_pvoid_t), TPTR(data)) sep \
286 ACTION(SIMCALL_PROCESS_AUTO_RESTART_SET, process_auto_restart_set, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t), TINT(auto_restart)) sep \
287 ACTION(SIMCALL_PROCESS_RESTART, process_restart, WITH_ANSWER, TSPEC(result, smx_process_t), TSPEC(process, smx_process_t)) sep \
288 ACTION(SIMCALL_RDV_CREATE, rdv_create, WITH_ANSWER, TSPEC(result, smx_rdv_t), TSTRING(name)) sep \
289 ACTION(SIMCALL_RDV_DESTROY, rdv_destroy, WITH_ANSWER, TVOID(result), TSPEC(rdv, smx_rdv_t)) sep \
290 ACTION(SIMCALL_RDV_GET_BY_NAME, rdv_get_by_name, WITH_ANSWER, TSPEC(result, smx_host_t), TSTRING(name)) sep \
291 ACTION(SIMCALL_RDV_COMM_COUNT_BY_HOST, rdv_comm_count_by_host, WITH_ANSWER, TUINT(result), TSPEC(rdv, smx_rdv_t), TSPEC(host, smx_host_t)) sep \
292 ACTION(SIMCALL_RDV_GET_HEAD, rdv_get_head, WITH_ANSWER, TSPEC(result, smx_action_t), TSPEC(rdv, smx_rdv_t)) sep \
293 ACTION(SIMCALL_RDV_SET_RECV, rdv_set_receiver, WITH_ANSWER, TVOID(result), TSPEC(rdv, smx_rdv_t), TSPEC(receiver, smx_process_t)) sep \
294 ACTION(SIMCALL_RDV_GET_RECV, rdv_get_receiver, WITH_ANSWER, TSPEC(result, smx_process_t), TSPEC(rdv, smx_rdv_t)) sep \
295 ACTION(SIMCALL_COMM_IPROBE, comm_iprobe, WITH_ANSWER, TSPEC(result, smx_action_t), TSPEC(rdv, smx_rdv_t), TINT(src), TINT(tag), TSPEC(match_fun, simix_match_func_t), TPTR(data)) sep \
296 ACTION(SIMCALL_COMM_SEND, comm_send, WITHOUT_ANSWER, TVOID(result), TSPEC(rdv, smx_rdv_t), TDOUBLE(task_size), TDOUBLE(rate), TPTR(src_buff), TSIZE(src_buff_size), TSPEC(match_fun, simix_match_func_t), TPTR(data), TDOUBLE(timeout)) sep \
297 ACTION(SIMCALL_COMM_ISEND, comm_isend, WITH_ANSWER, TSPEC(result, smx_action_t), TSPEC(rdv, smx_rdv_t), TDOUBLE(task_size), TDOUBLE(rate), TPTR(src_buff), TSIZE(src_buff_size), TSPEC(match_fun, simix_match_func_t), TSPEC(clean_fun, simix_clean_func_t), TPTR(data), TINT(detached)) sep \
298 ACTION(SIMCALL_COMM_RECV, comm_recv, WITHOUT_ANSWER, TVOID(result), TSPEC(rdv, smx_rdv_t), TPTR(dst_buff), TSPEC(dst_buff_size, size_t*), TSPEC(match_fun, simix_match_func_t), TPTR(data), TDOUBLE(timeout)) sep \
299 ACTION(SIMCALL_COMM_IRECV, comm_irecv, WITH_ANSWER, TSPEC(result, smx_action_t), TSPEC(rdv, smx_rdv_t), TPTR(dst_buff), TSPEC(dst_buff_size, size_t*), TSPEC(match_fun, simix_match_func_t), TPTR(data)) sep \
300 ACTION(SIMCALL_COMM_DESTROY, comm_destroy, WITH_ANSWER, TVOID(result), TSPEC(comm, smx_action_t)) sep \
301 ACTION(SIMCALL_COMM_CANCEL, comm_cancel, WITH_ANSWER, TVOID(result), TSPEC(comm, smx_action_t)) sep \
302 ACTION(SIMCALL_COMM_WAITANY, comm_waitany, WITHOUT_ANSWER, TINT(result), TSPEC(comms, xbt_dynar_t)) sep \
303 ACTION(SIMCALL_COMM_WAIT, comm_wait, WITHOUT_ANSWER, TVOID(result), TSPEC(comm, smx_action_t), TDOUBLE(timeout)) sep \
304 ACTION(SIMCALL_COMM_TEST, comm_test, WITHOUT_ANSWER, TINT(result), TSPEC(comm, smx_action_t)) sep \
305 ACTION(SIMCALL_COMM_TESTANY, comm_testany, WITHOUT_ANSWER, TINT(result), TSPEC(comms, xbt_dynar_t)) sep \
306 ACTION(SIMCALL_COMM_GET_REMAINS, comm_get_remains, WITH_ANSWER, TDOUBLE(result), TSPEC(comm, smx_action_t)) sep \
307 ACTION(SIMCALL_COMM_GET_STATE, comm_get_state, WITH_ANSWER, TINT(result), TSPEC(comm, smx_action_t)) sep \
308 ACTION(SIMCALL_COMM_GET_SRC_DATA, comm_get_src_data, WITH_ANSWER, TPTR(result), TSPEC(comm, smx_action_t)) sep \
309 ACTION(SIMCALL_COMM_GET_DST_DATA, comm_get_dst_data, WITH_ANSWER, TPTR(result), TSPEC(comm, smx_action_t)) sep \
310 ACTION(SIMCALL_COMM_GET_SRC_PROC, comm_get_src_proc, WITH_ANSWER, TSPEC(result, smx_process_t), TSPEC(comm, smx_action_t)) sep \
311 ACTION(SIMCALL_COMM_GET_DST_PROC, comm_get_dst_proc, WITH_ANSWER, TSPEC(result, smx_process_t), TSPEC(comm, smx_action_t)) sep \
312 ACTION(SIMCALL_MUTEX_INIT, mutex_init, WITH_ANSWER, TSPEC(result, smx_mutex_t)) sep \
313 ACTION(SIMCALL_MUTEX_DESTROY, mutex_destroy, WITH_ANSWER, TVOID(result), TSPEC(mutex, smx_mutex_t)) sep \
314 ACTION(SIMCALL_MUTEX_LOCK, mutex_lock, WITHOUT_ANSWER, TVOID(result), TSPEC(mutex, smx_mutex_t)) sep \
315 ACTION(SIMCALL_MUTEX_TRYLOCK, mutex_trylock, WITH_ANSWER, TINT(result), TSPEC(mutex, smx_mutex_t)) sep \
316 ACTION(SIMCALL_MUTEX_UNLOCK, mutex_unlock, WITH_ANSWER, TVOID(result), TSPEC(mutex, smx_mutex_t)) sep \
317 ACTION(SIMCALL_COND_INIT, cond_init, WITH_ANSWER, TSPEC(result, smx_cond_t)) sep \
318 ACTION(SIMCALL_COND_DESTROY, cond_destroy, WITH_ANSWER, TVOID(result), TSPEC(cond, smx_cond_t)) sep \
319 ACTION(SIMCALL_COND_SIGNAL, cond_signal, WITH_ANSWER, TVOID(result), TSPEC(cond, smx_cond_t)) sep \
320 ACTION(SIMCALL_COND_WAIT, cond_wait, WITHOUT_ANSWER, TVOID(result), TSPEC(cond, smx_cond_t), TSPEC(mutex, smx_mutex_t)) sep \
321 ACTION(SIMCALL_COND_WAIT_TIMEOUT, cond_wait_timeout, WITHOUT_ANSWER, TVOID(result), TSPEC(cond, smx_cond_t), TSPEC(mutex, smx_mutex_t), TDOUBLE(timeout)) sep \
322 ACTION(SIMCALL_COND_BROADCAST, cond_broadcast, WITH_ANSWER, TVOID(result), TSPEC(cond, smx_cond_t)) sep \
323 ACTION(SIMCALL_SEM_INIT, sem_init, WITH_ANSWER, TSPEC(result, smx_sem_t), TINT(capacity)) sep \
324 ACTION(SIMCALL_SEM_DESTROY, sem_destroy, WITH_ANSWER, TVOID(result), TSPEC(sem, smx_sem_t)) sep \
325 ACTION(SIMCALL_SEM_RELEASE, sem_release, WITH_ANSWER, TVOID(result), TSPEC(sem, smx_sem_t)) sep \
326 ACTION(SIMCALL_SEM_WOULD_BLOCK, sem_would_block, WITH_ANSWER, TINT(result), TSPEC(sem, smx_sem_t)) sep \
327 ACTION(SIMCALL_SEM_ACQUIRE, sem_acquire, WITHOUT_ANSWER, TVOID(result), TSPEC(sem, smx_sem_t)) sep \
328 ACTION(SIMCALL_SEM_ACQUIRE_TIMEOUT, sem_acquire_timeout, WITHOUT_ANSWER, TVOID(result), TSPEC(sem, smx_sem_t), TDOUBLE(timeout)) sep \
329 ACTION(SIMCALL_SEM_GET_CAPACITY, sem_get_capacity, WITH_ANSWER, TINT(result), TSPEC(sem, smx_sem_t)) sep \
330 ACTION(SIMCALL_FILE_READ, file_read, WITHOUT_ANSWER, TDOUBLE(result), TPTR(ptr), TSIZE(size), TSIZE(nmemb), TSPEC(stream, smx_file_t)) sep \
331 ACTION(SIMCALL_FILE_WRITE, file_write, WITHOUT_ANSWER, TSIZE(result), TCPTR(ptr), TSIZE(size), TSIZE(nmemb), TSPEC(stream, smx_file_t)) sep \
332 ACTION(SIMCALL_FILE_OPEN, file_open, WITHOUT_ANSWER, TSPEC(result, smx_file_t), TSTRING(mount), TSTRING(path), TSTRING(mode)) sep \
333 ACTION(SIMCALL_FILE_CLOSE, file_close, WITHOUT_ANSWER, TINT(result), TSPEC(fp, smx_file_t)) sep \
334 ACTION(SIMCALL_FILE_STAT, file_stat, WITHOUT_ANSWER, TINT(result), TSPEC(fd, smx_file_t), TSPEC(buf, s_file_stat_t*)) sep \
335 ACTION(SIMCALL_FILE_UNLINK, file_unlink, WITHOUT_ANSWER, TINT(result), TSPEC(fd, smx_file_t)) sep \
336 ACTION(SIMCALL_FILE_LS, file_ls, WITHOUT_ANSWER, TSPEC(result, xbt_dict_t), TSTRING(mount), TSTRING(path)) sep \
337 ACTION(SIMCALL_ASR_GET_PROPERTIES, asr_get_properties, WITH_ANSWER, TSPEC(result, xbt_dict_t), TSTRING(name)) sep 
338
339 /* SIMCALL_COMM_IS_LATENCY_BOUNDED and SIMCALL_SET_CATEGORY make things complicated
340  * because they are not always present */
341 #ifdef HAVE_LATENCY_BOUND_TRACKING
342 #define SIMCALL_LIST2(ACTION, sep) \
343 ACTION(SIMCALL_COMM_IS_LATENCY_BOUNDED, comm_is_latency_bounded, WITH_ANSWER, TINT(result), TSPEC(comm, smx_action_t)) sep
344 #else
345 #define SIMCALL_LIST2(ACTION, sep)
346 #endif
347
348 #ifdef HAVE_TRACING
349 #define SIMCALL_LIST3(ACTION, sep) \
350 ACTION(SIMCALL_SET_CATEGORY, set_category, WITH_ANSWER, TVOID(result), TSPEC(action, smx_action_t), TSTRING(category)) sep
351 #else
352 #define SIMCALL_LIST3(ACTION, sep)
353 #endif
354
355 #ifdef HAVE_MC
356 #define SIMCALL_LIST4(ACTION, sep) \
357 ACTION(SIMCALL_MC_SNAPSHOT, mc_snapshot, WITH_ANSWER, TPTR(result)) sep \
358 ACTION(SIMCALL_MC_COMPARE_SNAPSHOTS, mc_compare_snapshots, WITH_ANSWER, TINT(result), TPTR(s1), TPTR(s2)) sep 
359 #else
360 #define SIMCALL_LIST4(ACTION, sep)
361 #endif
362
363 /* SIMCALL_LIST is the final macro to use */
364 #define SIMCALL_LIST(ACTION, ...) \
365   SIMCALL_LIST1(ACTION, ##__VA_ARGS__)\
366   SIMCALL_LIST2(ACTION, ##__VA_ARGS__)\
367   SIMCALL_LIST3(ACTION, ##__VA_ARGS__)\
368   SIMCALL_LIST4(ACTION, ##__VA_ARGS__)
369
370
371 /* you can redefine the following macro differently to generate something else
372  * with the list of enumeration values (e.g. a table of strings or a table of function pointers) */
373 #define SIMCALL_ENUM_ELEMENT(x, y) x
374
375 /**
376  * \brief All possible simcalls.
377  */
378 typedef enum {
379 SIMCALL_NONE,
380 SIMCALL_LIST(SIMCALL_ENUM, SIMCALL_SEP_COMMA)
381 SIMCALL_NEW_API_INIT,
382 NUM_SIMCALLS
383 } e_smx_simcall_t;
384
385 typedef int (*simix_match_func_t)(void *, void *, smx_action_t);
386 typedef void (*simix_clean_func_t)(void *);
387
388 /* Pack all possible scalar types in an union */
389 union u_smx_scalar {
390   char            c;
391   const char*     cc;
392   short           s;
393   int             i;
394   long            l;
395   unsigned char   uc;
396   unsigned short  us;
397   unsigned int    ui;
398   unsigned long   ul;
399   float           f;
400   double          d;
401   size_t          si;
402   void*           p;
403   const void*     cp;
404 };
405
406 /**
407  * \brief Represents a simcall to the kernel.
408  */
409 typedef struct s_smx_simcall {
410   e_smx_simcall_t call;
411   smx_process_t issuer;
412   int mc_value;
413   union u_smx_scalar *args;
414   union u_smx_scalar result;
415   //FIXME: union u_smx_scalar retval;
416   union {
417     struct {
418       const char* param1;
419       double param2;
420       int result;
421     } new_api;
422
423   };
424 } s_smx_simcall_t, *smx_simcall_t;
425
426 SIMCALL_LIST(SIMCALL_RES_GETSET, SIMCALL_SEP_NOTHING)
427 SIMCALL_LIST(SIMCALL_ARG_GETSET, SIMCALL_SEP_NOTHING)
428
429 /******************************** General *************************************/
430
431 void SIMIX_simcall_push(smx_process_t self);
432 void SIMIX_simcall_answer(smx_simcall_t);
433 void SIMIX_simcall_pre(smx_simcall_t, int);
434 void SIMIX_simcall_post(smx_action_t);
435 smx_simcall_t SIMIX_simcall_mine(void);
436 const char *SIMIX_simcall_name(e_smx_simcall_t kind);
437 //TOFIX put it in a better place
438 xbt_dict_t SIMIX_pre_asr_get_properties(smx_simcall_t simcall, const char *name);
439
440 /*************************** New simcall interface ****************************/
441
442 smx_simcall_t __SIMIX_simcall(e_smx_simcall_t simcall_id, u_smx_scalar_t *args);
443
444 typedef smx_action_t (*simcall_handler_t)(u_smx_scalar_t *);
445
446 extern const char *simcall_types[];
447 extern simcall_handler_t simcall_table[];
448
449 #endif
450