Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
8fb5b34e81204009a9b1b63c498ad14bf81f749c
[simgrid.git] / src / simix / smx_user.c
1 /* smx_user.c - public interface to simix                                   */
2
3 /* Copyright (c) 2010, 2011. Da SimGrid team. All rights reserved.          */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7 #ifndef _SVID_SOURCE
8 #  define _SVID_SOURCE    /* strdup() */
9 #endif
10 #ifndef _ISOC99_SOURCE
11 #  define _ISOC99_SOURCE  /* isfinite() */
12 #endif
13 #ifndef _ISO_C99_SOURCE
14 #  define _ISO_C99_SOURCE /* isfinite() */
15 #endif
16 #include <math.h>         /* isfinite() */
17
18 #include "smx_private.h"
19 #include "mc/mc.h"
20 #include "xbt/ex.h"
21
22 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix);
23
24 static const char* simcall_names[] = {
25 #undef SIMCALL_ENUM_ELEMENT
26 #define SIMCALL_ENUM_ELEMENT(x) #x /* generate strings from the enumeration values */
27 SIMCALL_LIST
28 #undef SIMCALL_ENUM_ELEMENT
29 };
30
31 /**
32  * \ingroup simix_host_management
33  * \brief Returns a host given its name.
34  *
35  * \param name The name of the host to get
36  * \return The corresponding host
37  */
38 smx_host_t simcall_host_get_by_name(const char *name)
39 {
40   smx_simcall_t simcall = SIMIX_simcall_mine();
41
42   simcall->call = SIMCALL_HOST_GET_BY_NAME;
43   simcall->host_get_by_name.name = name;
44   if(MC_IS_ENABLED) /* Initialize result to NULL for snapshot comparison done during simcall */
45     simcall->host_get_by_name.result = NULL;
46   SIMIX_simcall_push(simcall->issuer);
47   return simcall->host_get_by_name.result;
48 }
49
50 /**
51  * \ingroup simix_host_management
52  * \brief Returns the name of a host.
53  *
54  * \param host A SIMIX host
55  * \return The name of this host
56  */
57 const char* simcall_host_get_name(smx_host_t host)
58 {
59   smx_simcall_t simcall = SIMIX_simcall_mine();
60
61   simcall->call = SIMCALL_HOST_GET_NAME;
62   simcall->host_get_name.host = host;
63   if(MC_IS_ENABLED) /* Initialize result to NULL for snapshot comparison done during simcall */
64     simcall->host_get_name.result = NULL;
65   SIMIX_simcall_push(simcall->issuer);
66   return simcall->host_get_name.result;
67 }
68
69 /**
70  * \ingroup simix_host_management
71  * \brief Returns a dict of the properties assigned to a host.
72  *
73  * \param host A host
74  * \return The properties of this host
75  */
76 xbt_dict_t simcall_host_get_properties(smx_host_t host)
77 {
78   smx_simcall_t simcall = SIMIX_simcall_mine();
79
80   simcall->call = SIMCALL_HOST_GET_PROPERTIES;
81   simcall->host_get_properties.host = host;
82   if(MC_IS_ENABLED) /* Initialize result to NULL for snapshot comparison done during simcall */
83     simcall->host_get_properties.result = NULL;
84   SIMIX_simcall_push(simcall->issuer);
85   return simcall->host_get_properties.result;
86 }
87
88 /**
89  * \ingroup simix_host_management
90  * \brief Returns a dict of the properties assigned to a router or AS.
91  *
92  * \param asr name of the router or AS
93  * \return The properties
94  */
95 xbt_dict_t simcall_asr_get_properties(const char *name)
96 {
97   smx_simcall_t simcall = SIMIX_simcall_mine();
98
99   simcall->call = SIMCALL_ASR_GET_PROPERTIES;
100   simcall->asr_get_properties.name = name;
101   if(MC_IS_ENABLED) /* Initialize result to NULL for snapshot comparison done during simcall */
102     simcall->asr_get_properties.result = NULL;
103   SIMIX_simcall_push(simcall->issuer);
104   return simcall->asr_get_properties.result;
105 }
106
107
108 /**
109  * \ingroup simix_host_management
110  * \brief Returns the speed of the processor.
111  *
112  * The speed returned does not take into account the current load on the machine.
113  * \param host A SIMIX host
114  * \return The speed of this host (in Mflop/s)
115  */
116 double simcall_host_get_speed(smx_host_t host)
117 {
118   smx_simcall_t simcall = SIMIX_simcall_mine();
119
120   simcall->call = SIMCALL_HOST_GET_SPEED;
121   simcall->host_get_speed.host = host;
122   if(MC_IS_ENABLED) /* Initialize result to a default value for snapshot comparison done during simcall */
123     simcall->host_get_speed.result = 0.0;
124   SIMIX_simcall_push(simcall->issuer);
125   return simcall->host_get_speed.result;
126 }
127
128 /**
129  * \ingroup simix_host_management
130  * \brief Returns the available speed of the processor.
131  *
132  * \return Speed currently available (in Mflop/s)
133  */
134 double simcall_host_get_available_speed(smx_host_t host)
135 {
136   smx_simcall_t simcall = SIMIX_simcall_mine();
137
138   simcall->call = SIMCALL_HOST_GET_AVAILABLE_SPEED;
139   simcall->host_get_available_speed.host = host;
140   if(MC_IS_ENABLED) /* Initialize result to a default value for snapshot comparison done during simcall */
141     simcall->host_get_available_speed.result = 0.0;
142   SIMIX_simcall_push(simcall->issuer);
143   return simcall->host_get_available_speed.result;
144 }
145
146 /**
147  * \ingroup simix_host_management
148  * \brief Returns the state of a host.
149  *
150  * Two states are possible: 1 if the host is active or 0 if it has crashed.
151  * \param host A SIMIX host
152  * \return 1 if the host is available, 0 otherwise
153  */
154 int simcall_host_get_state(smx_host_t host)
155 {
156   smx_simcall_t simcall = SIMIX_simcall_mine();
157
158   simcall->call = SIMCALL_HOST_GET_STATE;
159   simcall->host_get_state.host = host;
160   if(MC_IS_ENABLED) /* Initialize result to a default value for snapshot comparison done during simcall */
161     simcall->host_get_state.result = -1;
162   SIMIX_simcall_push(simcall->issuer);
163   return simcall->host_get_state.result;
164 }
165
166 /**
167  * \ingroup simix_host_management
168  * \brief Returns the user data associated to a host.
169  *
170  * \param host SIMIX host
171  * \return the user data of this host
172  */
173 void* simcall_host_get_data(smx_host_t host)
174 {
175   smx_simcall_t simcall = SIMIX_simcall_mine();
176
177   simcall->call = SIMCALL_HOST_GET_DATA;
178   simcall->host_get_data.host = host;
179   if(MC_IS_ENABLED) /* Initialize result to NULL for snapshot comparison done during simcall */
180     simcall->host_get_data.result = NULL;
181   SIMIX_simcall_push(simcall->issuer);
182   return simcall->host_get_data.result;
183 }
184
185 /**
186  * \ingroup simix_host_management
187  * \brief Sets the user data associated to a host.
188  *
189  * The host must not have previous user data associated to it.
190  * \param host A SIMIX host
191  * \param data The user data to set
192  */
193 void simcall_host_set_data(smx_host_t host, void *data)
194 {
195   smx_simcall_t simcall = SIMIX_simcall_mine();
196
197   simcall->call = SIMCALL_HOST_SET_DATA;
198   simcall->host_set_data.host = host;
199   simcall->host_set_data.data = data;
200   SIMIX_simcall_push(simcall->issuer);
201 }
202
203 /**
204  * \ingroup simix_host_management
205  * \brief Creates an action that executes some computation of an host.
206  *
207  * This function creates a SURF action and allocates the data necessary
208  * to create the SIMIX action. It can raise a host_error exception if the host crashed.
209  *
210  * \param name Name of the execution action to create
211  * \param host SIMIX host where the action will be executed
212  * \param computation_amount amount Computation amount (in bytes)
213  * \param priority computation priority
214  * \return A new SIMIX execution action
215  */
216 smx_action_t simcall_host_execute(const char *name, smx_host_t host,
217                                     double computation_amount,
218                                     double priority)
219 {
220   /* checking for infinite values */
221   xbt_assert(isfinite(computation_amount), "computation_amount is not finite!");
222   xbt_assert(isfinite(priority), "priority is not finite!");
223   
224   smx_simcall_t simcall = SIMIX_simcall_mine();
225
226   simcall->call = SIMCALL_HOST_EXECUTE;
227   simcall->host_execute.name = name;
228   simcall->host_execute.host = host;
229   simcall->host_execute.computation_amount = computation_amount;
230   simcall->host_execute.priority = priority;
231   if(MC_IS_ENABLED) /* Initialize result to NULL for snapshot comparison done during simcall */
232     simcall->host_execute.result = NULL;
233   SIMIX_simcall_push(simcall->issuer);
234   return simcall->host_execute.result;
235 }
236
237 /**
238  * \ingroup simix_host_management
239  * \brief Creates an action that may involve parallel computation on
240  * several hosts and communication between them.
241  *
242  * \param name Name of the execution action to create
243  * \param host_nb Number of hosts where the action will be executed
244  * \param host_list Array (of size host_nb) of hosts where the action will be executed
245  * \param computation_amount Array (of size host_nb) of computation amount of hosts (in bytes)
246  * \param communication_amount Array (of size host_nb * host_nb) representing the communication
247  * amount between each pair of hosts
248  * \param amount the SURF action amount
249  * \param rate the SURF action rate
250  * \return A new SIMIX execution action
251  */
252 smx_action_t simcall_host_parallel_execute(const char *name,
253                                          int host_nb,
254                                          smx_host_t *host_list,
255                                          double *computation_amount,
256                                          double *communication_amount,
257                                          double amount,
258                                          double rate)
259 {
260   int i,j;
261   /* checking for infinite values */
262   for (i = 0 ; i < host_nb ; ++i) {
263      xbt_assert(isfinite(computation_amount[i]), "computation_amount[%d] is not finite!", i);
264      for (j = 0 ; j < host_nb ; ++j) {
265         xbt_assert(isfinite(communication_amount[i + host_nb * j]), 
266              "communication_amount[%d+%d*%d] is not finite!", i, host_nb, j);
267      }   
268   }   
269  
270   xbt_assert(isfinite(amount), "amount is not finite!");
271   xbt_assert(isfinite(rate), "rate is not finite!");
272   
273   smx_simcall_t simcall = SIMIX_simcall_mine();
274
275   simcall->call = SIMCALL_HOST_PARALLEL_EXECUTE;
276   simcall->host_parallel_execute.name = name;
277   simcall->host_parallel_execute.host_nb = host_nb;
278   simcall->host_parallel_execute.host_list = host_list;
279   simcall->host_parallel_execute.computation_amount = computation_amount;
280   simcall->host_parallel_execute.communication_amount = communication_amount;
281   simcall->host_parallel_execute.amount = amount;
282   simcall->host_parallel_execute.rate = rate;
283   if(MC_IS_ENABLED) /* Initialize result to NULL for snapshot comparison done during simcall */
284     simcall->host_parallel_execute.result = NULL;
285   SIMIX_simcall_push(simcall->issuer);
286   return simcall->host_parallel_execute.result;
287 }
288
289 /**
290  * \ingroup simix_host_management
291  * \brief Destroys an execution action.
292  *
293  * Destroys an action, freing its memory. This function cannot be called if there are a conditional waiting for it.
294  * \param execution The execution action to destroy
295  */
296 void simcall_host_execution_destroy(smx_action_t execution)
297 {
298   smx_simcall_t simcall = SIMIX_simcall_mine();
299
300   simcall->call = SIMCALL_HOST_EXECUTION_DESTROY;
301   simcall->host_execution_destroy.execution = execution;
302   SIMIX_simcall_push(simcall->issuer);
303 }
304
305 /**
306  * \ingroup simix_host_management
307  * \brief Cancels an execution action.
308  *
309  * This functions stops the execution. It calls a surf function.
310  * \param execution The execution action to cancel
311  */
312 void simcall_host_execution_cancel(smx_action_t execution)
313 {
314   smx_simcall_t simcall = SIMIX_simcall_mine();
315
316   simcall->call = SIMCALL_HOST_EXECUTION_CANCEL;
317   simcall->host_execution_cancel.execution = execution;
318   SIMIX_simcall_push(simcall->issuer);
319 }
320
321 /**
322  * \ingroup simix_host_management
323  * \brief Returns how much of an execution action remains to be done.
324  *
325  * \param execution The execution action
326  * \return The remaining amount
327  */
328 double simcall_host_execution_get_remains(smx_action_t execution)
329 {
330   smx_simcall_t simcall = SIMIX_simcall_mine();
331
332   simcall->call = SIMCALL_HOST_EXECUTION_GET_REMAINS;
333   simcall->host_execution_get_remains.execution = execution;
334   if(MC_IS_ENABLED) /* Initializeialize result to a default value for snapshot comparison done during simcall */
335     simcall->host_execution_get_remains.result = 0.0;
336   SIMIX_simcall_push(simcall->issuer);
337   return simcall->host_execution_get_remains.result;
338 }
339
340 /**
341  * \ingroup simix_host_management
342  * \brief Returns the state of an execution action.
343  *
344  * \param execution The execution action
345  * \return The state
346  */
347 e_smx_state_t simcall_host_execution_get_state(smx_action_t execution)
348 {
349   smx_simcall_t simcall = SIMIX_simcall_mine();
350
351   simcall->call = SIMCALL_HOST_EXECUTION_GET_STATE;
352   simcall->host_execution_get_state.execution = execution;
353   simcall->host_execution_get_state.result = -1;
354   SIMIX_simcall_push(simcall->issuer);
355   return simcall->host_execution_get_state.result;
356 }
357
358 /**
359  * \ingroup simix_host_management
360  * \brief Changes the priority of an execution action.
361  *
362  * This functions changes the priority only. It calls a surf function.
363  * \param execution The execution action
364  * \param priority The new priority
365  */
366 void simcall_host_execution_set_priority(smx_action_t execution, double priority)
367 {
368   /* checking for infinite values */
369   xbt_assert(isfinite(priority), "priority is not finite!");
370   
371   smx_simcall_t simcall = SIMIX_simcall_mine();
372
373   simcall->call = SIMCALL_HOST_EXECUTION_SET_PRIORITY;
374   simcall->host_execution_set_priority.execution = execution;
375   simcall->host_execution_set_priority.priority = priority;
376   SIMIX_simcall_push(simcall->issuer);
377 }
378
379 /**
380  * \ingroup simix_host_management
381  * \brief Waits for the completion of an execution action and destroy it.
382  *
383  * \param execution The execution action
384  */
385 e_smx_state_t simcall_host_execution_wait(smx_action_t execution)
386 {
387   smx_simcall_t simcall = SIMIX_simcall_mine();
388
389   simcall->call = SIMCALL_HOST_EXECUTION_WAIT;
390   simcall->host_execution_wait.execution = execution;
391   if(MC_IS_ENABLED) /* Initialize result to a default value for snapshot comparison done during simcall */
392     simcall->host_execution_wait.result = -1;
393   SIMIX_simcall_push(simcall->issuer);
394   return simcall->host_execution_wait.result;
395 }
396
397 /**
398  * \ingroup simix_process_management
399  * \brief Creates and runs a new SIMIX process.
400  *
401  * The structure and the corresponding thread are created and put in the list of ready processes.
402  *
403  * \param process the process created will be stored in this pointer
404  * \param name a name for the process. It is for user-level information and can be NULL.
405  * \param code the main function of the process
406  * \param data a pointer to any data one may want to attach to the new object. It is for user-level information and can be NULL.
407  * It can be retrieved with the function \ref simcall_process_get_data.
408  * \param hostname name of the host where the new agent is executed.
409  * \param kill_time time when the process is killed
410  * \param argc first argument passed to \a code
411  * \param argv second argument passed to \a code
412  * \param properties the properties of the process
413  * \param auto_restart either it is autorestarting or not.
414  */
415 void simcall_process_create(smx_process_t *process, const char *name,
416                               xbt_main_func_t code,
417                               void *data,
418                               const char *hostname,
419                               double kill_time,
420                               int argc, char **argv,
421                               xbt_dict_t properties,
422                               int auto_restart)
423 {
424   smx_simcall_t simcall = SIMIX_simcall_mine();
425
426   simcall->call = SIMCALL_PROCESS_CREATE;
427   simcall->process_create.process = process;
428   simcall->process_create.name = name;
429   simcall->process_create.code = code;
430   simcall->process_create.data = data;
431   simcall->process_create.hostname = hostname;
432   simcall->process_create.kill_time = kill_time;
433   simcall->process_create.argc = argc;
434   simcall->process_create.argv = argv;
435   simcall->process_create.properties = properties;
436   simcall->process_create.auto_restart = auto_restart;
437   SIMIX_simcall_push(simcall->issuer);
438 }
439
440 /**
441  * \ingroup simix_process_management
442  * \brief Kills a SIMIX process.
443  *
444  * This function simply kills a  process.
445  *
446  * \param process poor victim
447  */
448 void simcall_process_kill(smx_process_t process)
449 {
450   smx_simcall_t simcall = SIMIX_simcall_mine();
451
452   simcall->call = SIMCALL_PROCESS_KILL;
453   simcall->process_kill.process = process;
454   SIMIX_simcall_push(simcall->issuer);
455 }
456
457 /**
458  * \ingroup simix_process_management
459  * \brief Kills all SIMIX processes.
460  */
461 void simcall_process_killall(void)
462 {
463   smx_simcall_t simcall = SIMIX_simcall_mine();
464
465   simcall->call = SIMCALL_PROCESS_KILLALL;
466   SIMIX_simcall_push(simcall->issuer);
467 }
468
469 /**
470  * \ingroup simix_process_management
471  * \brief Cleans up a SIMIX process.
472  * \param process poor victim (must have already been killed)
473  */
474 void simcall_process_cleanup(smx_process_t process)
475 {
476   smx_simcall_t simcall = SIMIX_simcall_mine();
477
478   simcall->call = SIMCALL_PROCESS_CLEANUP;
479   simcall->process_cleanup.process = process;
480   SIMIX_simcall_push(simcall->issuer);
481 }
482
483 /**
484  * \ingroup simix_process_management
485  * \brief Migrates an agent to another location.
486  *
487  * This function changes the value of the host on which \a process is running.
488  *
489  * \param process the process to migrate
490  * \param dest name of the new host
491  */
492 void simcall_process_change_host(smx_process_t process, smx_host_t dest)
493 {
494   smx_simcall_t simcall = SIMIX_simcall_mine();
495
496   simcall->call = SIMCALL_PROCESS_CHANGE_HOST;
497   simcall->process_change_host.process = process;
498   simcall->process_change_host.dest = dest;
499   SIMIX_simcall_push(simcall->issuer);
500 }
501
502 /**
503  * \ingroup simix_process_management
504  * \brief Suspends a process.
505  *
506  * This function suspends the process by suspending the action
507  * it was waiting for completion.
508  *
509  * \param process a SIMIX process
510  */
511 void simcall_process_suspend(smx_process_t process)
512 {
513   xbt_assert(process, "Invalid parameters");
514
515   smx_simcall_t simcall = SIMIX_simcall_mine();
516
517   simcall->call = SIMCALL_PROCESS_SUSPEND;
518   simcall->process_suspend.process = process;
519   SIMIX_simcall_push(simcall->issuer);
520 }
521
522 /**
523  * \ingroup simix_process_management
524  * \brief Resumes a suspended process.
525  *
526  * This function resumes a suspended process by resuming the action
527  * it was waiting for completion.
528  *
529  * \param process a SIMIX process
530  */
531 void simcall_process_resume(smx_process_t process)
532 {
533   smx_simcall_t simcall = SIMIX_simcall_mine();
534
535   simcall->call = SIMCALL_PROCESS_RESUME;
536   simcall->process_resume.process = process;
537   SIMIX_simcall_push(simcall->issuer);
538 }
539
540 /**
541  * \ingroup simix_process_management
542  * \brief Returns the amount of SIMIX processes in the system
543  *
544  * Maestro internal process is not counted, only user code processes are
545  */
546 int simcall_process_count(void)
547 {
548   smx_simcall_t simcall = SIMIX_simcall_mine();
549
550   simcall->call = SIMCALL_PROCESS_COUNT;
551   if(MC_IS_ENABLED) /* Initialize result to a default value for snapshot comparison done during simcall */
552     simcall->process_count.result = -1;
553   SIMIX_simcall_push(simcall->issuer);
554   return simcall->process_count.result;
555 }
556
557 /**
558  * \ingroup simix_process_management
559  * \brief Return the user data of a #smx_process_t.
560  * \param process a SIMIX process
561  * \return the user data of this process
562  */
563 void* simcall_process_get_data(smx_process_t process)
564 {
565   if (process == SIMIX_process_self()) {
566     /* avoid a simcall if this function is called by the process itself */
567     return SIMIX_process_get_data(process);
568   }
569
570   smx_simcall_t simcall = SIMIX_simcall_mine();
571
572   simcall->call = SIMCALL_PROCESS_GET_DATA;
573   simcall->process_get_data.process = process;
574   if(MC_IS_ENABLED) /* Initialize result to NULL for snapshot comparison done during simcall */
575     simcall->process_get_data.result = NULL;
576   SIMIX_simcall_push(simcall->issuer);
577   return simcall->process_get_data.result;
578 }
579
580 /**
581  * \ingroup simix_process_management
582  * \brief Set the user data of a #smx_process_t.
583  *
584  * This functions sets the user data associated to \a process.
585  * \param process SIMIX process
586  * \param data User data
587  */
588 void simcall_process_set_data(smx_process_t process, void *data)
589 {
590   if (process == SIMIX_process_self()) {
591     /* avoid a simcall if this function is called by the process itself */
592     SIMIX_process_self_set_data(process, data);
593   }
594   else {
595
596     smx_simcall_t simcall = SIMIX_simcall_mine();
597
598     simcall->call = SIMCALL_PROCESS_SET_DATA;
599     simcall->process_set_data.process = process;
600     simcall->process_set_data.data = data;
601     SIMIX_simcall_push(simcall->issuer);
602   }
603 }
604
605 /**
606  * \ingroup simix_process_management
607  * \brief Set the kill time of a process.
608  * \param process a process
609  * \param kill_time a double
610  */
611 void simcall_process_set_kill_time(smx_process_t process, double kill_time)
612 {
613
614   if (kill_time > SIMIX_get_clock()) {
615     if (simix_global->kill_process_function) {
616       XBT_DEBUG("Set kill time %f for process %s(%s)",kill_time, process->name,
617           process->smx_host->name);
618       SIMIX_timer_set(kill_time, simix_global->kill_process_function, process);
619     }
620   }
621 }
622
623 /**
624  * \ingroup simix_process_management
625  * \brief Return the location on which an agent is running.
626  *
627  * This functions returns the smx_host_t corresponding to the location on which
628  * \a process is running.
629  * \param process SIMIX process
630  * \return SIMIX host
631  */
632 smx_host_t simcall_process_get_host(smx_process_t process)
633 {
634   smx_simcall_t simcall = SIMIX_simcall_mine();
635
636   simcall->call = SIMCALL_PROCESS_GET_HOST;
637   simcall->process_get_host.process = process;
638   if(MC_IS_ENABLED) /* Initialize result to NULL for snapshot comparison done during simcall */
639     simcall->process_get_host.result = NULL;
640   SIMIX_simcall_push(simcall->issuer);
641   return simcall->process_get_host.result;
642 }
643
644 /**
645  * \ingroup simix_process_management
646  * \brief Return the name of an agent.
647  *
648  * This functions checks whether \a process is a valid pointer or not and return its name.
649  * \param process SIMIX process
650  * \return The process name
651  */
652 const char* simcall_process_get_name(smx_process_t process)
653 {
654   if (process == SIMIX_process_self()) {
655     /* avoid a simcall if this function is called by the process itself */
656     return process->name;
657   }
658
659   smx_simcall_t simcall = SIMIX_simcall_mine();
660
661   simcall->call = SIMCALL_PROCESS_GET_NAME;
662   simcall->process_get_name.process = process;
663   if(MC_IS_ENABLED) /* Initialize result to NULL for snapshot comparison done during simcall */
664     simcall->process_get_name.result = NULL;
665   SIMIX_simcall_push(simcall->issuer);
666   return simcall->process_get_name.result;
667 }
668
669 /**
670  * \ingroup simix_process_management
671  * \brief Returns true if the process is suspended .
672  *
673  * This checks whether a process is suspended or not by inspecting the task on which it was waiting for the completion.
674  * \param process SIMIX process
675  * \return 1, if the process is suspended, else 0.
676  */
677 int simcall_process_is_suspended(smx_process_t process)
678 {
679   smx_simcall_t simcall = SIMIX_simcall_mine();
680
681   simcall->call = SIMCALL_PROCESS_IS_SUSPENDED;
682   simcall->process_is_suspended.process = process;
683   if(MC_IS_ENABLED) /* Initialize result to a default value for snapshot comparison done during simcall */
684     simcall->process_is_suspended.result = -1;
685   SIMIX_simcall_push(simcall->issuer);
686   return simcall->process_is_suspended.result;
687 }
688
689 /**
690  * \ingroup simix_process_management
691  * \brief Return the properties
692  *
693  * This functions returns the properties associated with this process
694  */
695 xbt_dict_t simcall_process_get_properties(smx_process_t process)
696 {
697   smx_simcall_t simcall = SIMIX_simcall_mine();
698
699   simcall->call = SIMCALL_PROCESS_GET_PROPERTIES;
700   simcall->process_get_properties.process = process;
701   if(MC_IS_ENABLED) /* Initialize result to NULL for snapshot comparison done during simcall */
702     simcall->process_get_properties.result = NULL;
703   SIMIX_simcall_push(simcall->issuer);
704   return simcall->process_get_properties.result;
705 }
706 /**
707  * \ingroup simix_process_management
708  * \brief Add an on_exit function
709  * Add an on_exit function which will be executed when the process exits/is killed.
710  */
711 XBT_PUBLIC(void) simcall_process_on_exit(smx_process_t process, int_f_pvoid_t fun, void *data)
712 {
713   smx_simcall_t simcall = SIMIX_simcall_mine();
714
715   simcall->call = SIMCALL_PROCESS_ON_EXIT;
716   simcall->process_on_exit.process = process;
717   simcall->process_on_exit.fun = fun;
718   simcall->process_on_exit.data = data;
719
720   SIMIX_simcall_push(simcall->issuer);
721 }
722 /**
723  * \ingroup simix_process_management
724  * \brief Sets the process to be auto-restarted or not by SIMIX when its host comes back up.
725  * Will restart the process when the host comes back up if auto_restart is set to 1.
726  */
727
728 XBT_PUBLIC(void) simcall_process_auto_restart_set(smx_process_t process, int auto_restart)
729 {
730   smx_simcall_t simcall = SIMIX_simcall_mine();
731
732   simcall->call = SIMCALL_PROCESS_AUTO_RESTART_SET;
733   simcall->process_auto_restart.process = process;
734   simcall->process_auto_restart.auto_restart = auto_restart;
735
736   SIMIX_simcall_push(simcall->issuer);
737 }
738 /**
739  * \ingroup simix_process_management
740  * \brief Restarts the process, killing it and starting it again from scratch.
741  */
742 XBT_PUBLIC(smx_process_t) simcall_process_restart(smx_process_t process)
743 {
744   smx_simcall_t simcall = SIMIX_simcall_mine();
745
746   simcall->call = SIMCALL_PROCESS_RESTART;
747   simcall->process_restart.process = process;
748   if(MC_IS_ENABLED) /* Initialize result to NULL for snapshot comparison done during simcall */
749     simcall->process_restart.result = NULL;
750
751   SIMIX_simcall_push(simcall->issuer);
752
753   return simcall->process_restart.result;
754 }
755 /**
756  * \ingroup simix_process_management
757  * \brief Creates a new sleep SIMIX action.
758  *
759  * This function creates a SURF action and allocates the data necessary
760  * to create the SIMIX action. It can raise a host_error exception if the
761  * host crashed. The default SIMIX name of the action is "sleep".
762  *
763  *   \param duration Time duration of the sleep.
764  *   \return A result telling whether the sleep was successful
765  */
766 e_smx_state_t simcall_process_sleep(double duration)
767 {
768   /* checking for infinite values */
769   xbt_assert(isfinite(duration), "duration is not finite!");
770   
771   smx_simcall_t simcall = SIMIX_simcall_mine();
772
773   simcall->call = SIMCALL_PROCESS_SLEEP;
774   simcall->process_sleep.duration = duration;
775   if(MC_IS_ENABLED) /* Initialize result to a default value for snapshot comparison done during simcall */
776     simcall->process_sleep.result = -1;
777   SIMIX_simcall_push(simcall->issuer);
778   return simcall->process_sleep.result;
779 }
780
781 /**
782  *  \ingroup simix_rdv_management
783  *  \brief Creates a new rendez-vous point
784  *  \param name The name of the rendez-vous point
785  *  \return The created rendez-vous point
786  */
787 smx_rdv_t simcall_rdv_create(const char *name)
788 {
789   smx_simcall_t simcall = SIMIX_simcall_mine();
790
791   simcall->call = SIMCALL_RDV_CREATE;
792   simcall->rdv_create.name = name;
793   if(MC_IS_ENABLED) /* Initialize result to NULL for snapshot comparison done during simcall */
794     simcall->rdv_create.result = NULL;
795
796   SIMIX_simcall_push(simcall->issuer);
797   return simcall->rdv_create.result;
798 }
799
800
801 /**
802  *  \ingroup simix_rdv_management
803  *  \brief Destroy a rendez-vous point
804  *  \param rdv The rendez-vous point to destroy
805  */
806 void simcall_rdv_destroy(smx_rdv_t rdv)
807 {
808   smx_simcall_t simcall = SIMIX_simcall_mine();
809
810   simcall->call = SIMCALL_RDV_DESTROY;
811   simcall->rdv_destroy.rdv = rdv;
812
813   SIMIX_simcall_push(simcall->issuer);
814 }
815 /**
816  *  \ingroup simix_rdv_management
817  *  \brief Returns a rendez-vous point knowing its name
818  */
819 smx_rdv_t simcall_rdv_get_by_name(const char *name)
820 {
821   xbt_assert(name != NULL, "Invalid parameter for simcall_rdv_get_by_name (name is NULL)");
822
823   /* FIXME: this is a horrible lost of performance, so we hack it out by
824    * skipping the simcall (for now). It works in parallel, it won't work on
825    * distributed but probably we will change MSG for that. */
826
827   /*
828   smx_simcall_t simcall = simcall_mine();
829   simcall->call = SIMCALL_RDV_GEY_BY_NAME;
830   simcall->rdv_get_by_name.name = name;
831   SIMIX_simcall_push(simcall->issuer);
832   return simcall->rdv_get_by_name.result;*/
833
834   return SIMIX_rdv_get_by_name(name);
835 }
836
837 /**
838  *  \ingroup simix_rdv_management
839  *  \brief Counts the number of communication actions of a given host pending
840  *         on a rendez-vous point.
841  *  \param rdv The rendez-vous point
842  *  \param host The host to be counted
843  *  \return The number of comm actions pending in the rdv
844  */
845 int simcall_rdv_comm_count_by_host(smx_rdv_t rdv, smx_host_t host)
846 {
847   smx_simcall_t simcall = SIMIX_simcall_mine();
848
849   simcall->call = SIMCALL_RDV_COMM_COUNT_BY_HOST;
850   simcall->rdv_comm_count_by_host.rdv = rdv;
851   simcall->rdv_comm_count_by_host.host = host;
852   if(MC_IS_ENABLED) /* Initialize result to a default value for snapshot comparison done during simcall */
853     simcall->rdv_comm_count_by_host.result = -1;
854
855   SIMIX_simcall_push(simcall->issuer);
856   return simcall->rdv_comm_count_by_host.result;
857 }
858
859 /**
860  *  \ingroup simix_rdv_management
861  *  \brief returns the communication at the head of the rendez-vous
862  *  \param rdv The rendez-vous point
863  *  \return The communication or NULL if empty
864  */
865 smx_action_t simcall_rdv_get_head(smx_rdv_t rdv)
866 {
867   smx_simcall_t simcall = SIMIX_simcall_mine();
868
869   simcall->call = SIMCALL_RDV_GET_HEAD;
870   simcall->rdv_get_head.rdv = rdv;
871   if(MC_IS_ENABLED) /* Initialize result to NULL for snapshot comparison done during simcall */
872     simcall->rdv_get_head.result = NULL;
873
874   SIMIX_simcall_push(simcall->issuer);
875   return simcall->rdv_get_head.result;
876 }
877
878 void simcall_rdv_set_receiver(smx_rdv_t rdv , smx_process_t process)
879 {
880   smx_simcall_t simcall = SIMIX_simcall_mine();
881
882   simcall->call = SIMCALL_RDV_SET_RECV;
883   simcall->rdv_set_rcv_proc.rdv = rdv;
884   simcall->rdv_set_rcv_proc.receiver = process;
885
886   SIMIX_simcall_push(simcall->issuer);
887 }
888
889 smx_process_t simcall_rdv_get_receiver(smx_rdv_t rdv)
890 {
891   smx_simcall_t simcall = SIMIX_simcall_mine();
892
893   simcall->call = SIMCALL_RDV_GET_RECV;
894   simcall->rdv_get_rcv_proc.rdv = rdv;
895   if(MC_IS_ENABLED) /* Initialize result to NULL for snapshot comparison done during simcall */
896     simcall->rdv_get_rcv_proc.result = NULL;
897
898   SIMIX_simcall_push(simcall->issuer);
899   return simcall->rdv_get_rcv_proc.result;
900 }
901
902 /**
903  * \ingroup simix_comm_management
904  */
905 void simcall_comm_send(smx_rdv_t rdv, double task_size, double rate,
906                          void *src_buff, size_t src_buff_size,
907                          int (*match_fun)(void *, void *, smx_action_t), void *data,
908                          double timeout)
909 {
910   /* checking for infinite values */
911   xbt_assert(isfinite(task_size), "task_size is not finite!");
912   xbt_assert(isfinite(rate), "rate is not finite!");
913   xbt_assert(isfinite(timeout), "timeout is not finite!");
914   
915   xbt_assert(rdv, "No rendez-vous point defined for send");
916
917   if (MC_IS_ENABLED) {
918     /* the model-checker wants two separate simcalls */
919     smx_action_t comm = simcall_comm_isend(rdv, task_size, rate,
920         src_buff, src_buff_size, match_fun, NULL, data, 0);
921     simcall_comm_wait(comm, timeout);
922   }
923   else {
924     smx_simcall_t simcall = SIMIX_simcall_mine();
925
926     simcall->call = SIMCALL_COMM_SEND;
927     simcall->comm_send.rdv = rdv;
928     simcall->comm_send.task_size = task_size;
929     simcall->comm_send.rate = rate;
930     simcall->comm_send.src_buff = src_buff;
931     simcall->comm_send.src_buff_size = src_buff_size;
932     simcall->comm_send.match_fun = match_fun;
933     simcall->comm_send.data = data;
934     simcall->comm_send.timeout = timeout;
935
936     SIMIX_simcall_push(simcall->issuer);
937   }
938 }
939 /**
940  * \ingroup simix_comm_management
941  */
942 smx_action_t simcall_comm_isend(smx_rdv_t rdv, double task_size, double rate,
943                               void *src_buff, size_t src_buff_size,
944                               int (*match_fun)(void *, void *, smx_action_t),
945                               void (*clean_fun)(void *),
946                               void *data,
947                               int detached)
948 {
949   /* checking for infinite values */
950   xbt_assert(isfinite(task_size), "task_size is not finite!");
951   xbt_assert(isfinite(rate), "rate is not finite!");
952   
953   xbt_assert(rdv, "No rendez-vous point defined for isend");
954
955   smx_simcall_t simcall = SIMIX_simcall_mine();
956
957   simcall->call = SIMCALL_COMM_ISEND;
958   simcall->comm_isend.rdv = rdv;
959   simcall->comm_isend.task_size = task_size;
960   simcall->comm_isend.rate = rate;
961   simcall->comm_isend.src_buff = src_buff;
962   simcall->comm_isend.src_buff_size = src_buff_size;
963   simcall->comm_isend.match_fun = match_fun;
964   simcall->comm_isend.clean_fun = clean_fun;
965   simcall->comm_isend.data = data;
966   simcall->comm_isend.detached = detached;
967   if(MC_IS_ENABLED) /* Initialize result to NULL for snapshot comparison done during simcall */
968     simcall->comm_isend.result = NULL;
969
970   SIMIX_simcall_push(simcall->issuer);
971   return simcall->comm_isend.result;
972 }
973 /**
974  * \ingroup simix_comm_management
975  */
976 void simcall_comm_recv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
977                          int (*match_fun)(void *, void *, smx_action_t), void *data, double timeout)
978 {
979   xbt_assert(isfinite(timeout), "timeout is not finite!");
980   xbt_assert(rdv, "No rendez-vous point defined for recv");
981
982   if (MC_IS_ENABLED) {
983     /* the model-checker wants two separate simcalls */
984     smx_action_t comm = simcall_comm_irecv(rdv, dst_buff, dst_buff_size,
985         match_fun, data);
986     simcall_comm_wait(comm, timeout);
987   }
988   else {
989     smx_simcall_t simcall = SIMIX_simcall_mine();
990
991     simcall->call = SIMCALL_COMM_RECV;
992     simcall->comm_recv.rdv = rdv;
993     simcall->comm_recv.dst_buff = dst_buff;
994     simcall->comm_recv.dst_buff_size = dst_buff_size;
995     simcall->comm_recv.match_fun = match_fun;
996     simcall->comm_recv.data = data;
997     simcall->comm_recv.timeout = timeout;
998
999     SIMIX_simcall_push(simcall->issuer);
1000   }
1001 }
1002 /**
1003  * \ingroup simix_comm_management
1004  */
1005 smx_action_t simcall_comm_irecv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
1006                                   int (*match_fun)(void *, void *, smx_action_t), void *data)
1007 {
1008   xbt_assert(rdv, "No rendez-vous point defined for irecv");
1009
1010   smx_simcall_t simcall = SIMIX_simcall_mine();
1011
1012   simcall->call = SIMCALL_COMM_IRECV;
1013   simcall->comm_irecv.rdv = rdv;
1014   simcall->comm_irecv.dst_buff = dst_buff;
1015   simcall->comm_irecv.dst_buff_size = dst_buff_size;
1016   simcall->comm_irecv.match_fun = match_fun;
1017   simcall->comm_irecv.data = data;
1018   if(MC_IS_ENABLED) /* Initialize result to NULL for snapshot comparison done during simcall */
1019     simcall->comm_irecv.result = NULL;
1020
1021   SIMIX_simcall_push(simcall->issuer);
1022   return simcall->comm_irecv.result;
1023 }
1024 void simcall_comm_destroy(smx_action_t comm)
1025 {
1026   xbt_assert(comm, "Invalid parameter");
1027
1028   /* FIXME remove this simcall type: comms are auto-destroyed now */
1029
1030   /*
1031   smx_simcall_t simcall = simcall_mine();
1032
1033   simcall->call = SIMCALL_COMM_DESTROY;
1034   simcall->comm_destroy.comm = comm;
1035
1036   SIMIX_simcall_push(simcall->issuer);
1037   */
1038 }
1039 /**
1040  * \ingroup simix_comm_management
1041  */
1042 void simcall_comm_cancel(smx_action_t comm)
1043 {
1044   smx_simcall_t simcall = SIMIX_simcall_mine();
1045
1046   simcall->call = SIMCALL_COMM_CANCEL;
1047   simcall->comm_cancel.comm = comm;
1048
1049   SIMIX_simcall_push(simcall->issuer);
1050 }
1051 /**
1052  * \ingroup simix_comm_management
1053  */
1054 unsigned int simcall_comm_waitany(xbt_dynar_t comms)
1055 {
1056   smx_simcall_t simcall = SIMIX_simcall_mine();
1057
1058   simcall->call = SIMCALL_COMM_WAITANY;
1059   simcall->comm_waitany.comms = comms;
1060   if(MC_IS_ENABLED) /* Initialize result to a default value for snapshot comparison done during simcall */
1061     simcall->comm_waitany.result = -1;
1062
1063   SIMIX_simcall_push(simcall->issuer);
1064   return simcall->comm_waitany.result;
1065 }
1066 /**
1067  * \ingroup simix_comm_management
1068  */
1069 int simcall_comm_testany(xbt_dynar_t comms)
1070 {
1071   smx_simcall_t simcall = SIMIX_simcall_mine();
1072   if (xbt_dynar_is_empty(comms))
1073     return -1;
1074
1075   simcall->call = SIMCALL_COMM_TESTANY;
1076   simcall->comm_testany.comms = comms;
1077     if(MC_IS_ENABLED) /* Initialize result to a default value for snapshot comparison done during simcall */
1078       simcall->comm_testany.result = -1;
1079
1080   SIMIX_simcall_push(simcall->issuer);
1081   return simcall->comm_testany.result;
1082 }
1083 /**
1084  * \ingroup simix_comm_management
1085  */
1086 void simcall_comm_wait(smx_action_t comm, double timeout)
1087 {
1088   xbt_assert(isfinite(timeout), "timeout is not finite!");
1089   
1090   smx_simcall_t simcall = SIMIX_simcall_mine();
1091
1092   simcall->call = SIMCALL_COMM_WAIT;
1093   simcall->comm_wait.comm = comm;
1094   simcall->comm_wait.timeout = timeout;
1095
1096   SIMIX_simcall_push(simcall->issuer);
1097 }
1098
1099 #ifdef HAVE_TRACING
1100 /**
1101  * \brief Set the category of an action.
1102  *
1103  * This functions changes the category only. It calls a surf function.
1104  * \param execution The execution action
1105  * \param category The tracing category
1106  */
1107 void simcall_set_category(smx_action_t action, const char *category)
1108 {
1109   if (category == NULL) {
1110     return;
1111   }
1112
1113   smx_simcall_t simcall = SIMIX_simcall_mine();
1114
1115   simcall->call = SIMCALL_SET_CATEGORY;
1116   simcall->set_category.action = action;
1117   simcall->set_category.category = category;
1118
1119   SIMIX_simcall_push(simcall->issuer);
1120 }
1121 #endif
1122 /**
1123  * \ingroup simix_comm_management
1124  *
1125  */
1126 int simcall_comm_test(smx_action_t comm)
1127 {
1128   smx_simcall_t simcall = SIMIX_simcall_mine();
1129
1130   simcall->call = SIMCALL_COMM_TEST;
1131   simcall->comm_test.comm = comm;
1132   if(MC_IS_ENABLED) /* Initialize result to a default value for snapshot comparison done during simcall */
1133     simcall->comm_test.result = -1;
1134
1135   SIMIX_simcall_push(simcall->issuer);
1136   return simcall->comm_test.result;
1137 }
1138 /**
1139  * \ingroup simix_comm_management
1140  *
1141  */
1142 double simcall_comm_get_remains(smx_action_t comm)
1143 {
1144   smx_simcall_t simcall = SIMIX_simcall_mine();
1145
1146   simcall->call = SIMCALL_COMM_GET_REMAINS;
1147   simcall->comm_get_remains.comm = comm;
1148   if(MC_IS_ENABLED) /* Initialize result to a default value for snapshot comparison done during simcall */
1149     simcall->comm_get_remains.result = 0.0;
1150
1151   SIMIX_simcall_push(simcall->issuer);
1152   return simcall->comm_get_remains.result;
1153 }
1154 /**
1155  * \ingroup simix_comm_management
1156  *
1157  */
1158 e_smx_state_t simcall_comm_get_state(smx_action_t comm)
1159 {
1160   smx_simcall_t simcall = SIMIX_simcall_mine();
1161
1162   simcall->call = SIMCALL_COMM_GET_STATE;
1163   simcall->comm_get_state.comm = comm;
1164   if(MC_IS_ENABLED) /* Initialize result to a default value for snapshot comparison done during simcall */
1165     simcall->comm_get_state.result = -1;
1166
1167   SIMIX_simcall_push(simcall->issuer);
1168   return simcall->comm_get_state.result;
1169 }
1170 /**
1171  * \ingroup simix_comm_management
1172  *
1173  */
1174 void *simcall_comm_get_src_data(smx_action_t comm)
1175 {
1176   smx_simcall_t simcall = SIMIX_simcall_mine();
1177
1178   simcall->call = SIMCALL_COMM_GET_SRC_DATA;
1179   simcall->comm_get_src_data.comm = comm;
1180   if(MC_IS_ENABLED) /* Initialize result to NULL for snapshot comparison done during simcall */
1181     simcall->comm_get_src_data.result = NULL;
1182
1183   SIMIX_simcall_push(simcall->issuer);
1184   return simcall->comm_get_src_data.result;
1185 }
1186 /**
1187  * \ingroup simix_comm_management
1188  *
1189  */
1190 void *simcall_comm_get_dst_data(smx_action_t comm)
1191 {
1192   smx_simcall_t simcall = SIMIX_simcall_mine();
1193
1194   simcall->call = SIMCALL_COMM_GET_DST_DATA;
1195   simcall->comm_get_dst_data.comm = comm;
1196   if(MC_IS_ENABLED) /* Initialize result to NULL for snapshot comparison done during simcall */
1197     simcall->comm_get_dst_data.result = NULL;
1198
1199   SIMIX_simcall_push(simcall->issuer);
1200   return simcall->comm_get_dst_data.result;
1201 }
1202 /**
1203  * \ingroup simix_comm_management
1204  *
1205  */
1206 smx_process_t simcall_comm_get_src_proc(smx_action_t comm)
1207 {
1208   smx_simcall_t simcall = SIMIX_simcall_mine();
1209
1210   simcall->call = SIMCALL_COMM_GET_SRC_PROC;
1211   simcall->comm_get_src_proc.comm = comm;
1212   if(MC_IS_ENABLED) /* Initialize result to NULL for snapshot comparison done during simcall */
1213     simcall->comm_get_src_proc.result = NULL;
1214
1215   SIMIX_simcall_push(simcall->issuer);
1216   return simcall->comm_get_src_proc.result;
1217 }
1218 /**
1219  * \ingroup simix_comm_management
1220  *
1221  */
1222 smx_process_t simcall_comm_get_dst_proc(smx_action_t comm)
1223 {
1224   smx_simcall_t simcall = SIMIX_simcall_mine();
1225
1226   simcall->call = SIMCALL_COMM_GET_DST_PROC;
1227   simcall->comm_get_dst_proc.comm = comm;
1228   if(MC_IS_ENABLED) /* Initialize result to NULL for snapshot comparison done during simcall */
1229     simcall->comm_get_dst_proc.result = NULL;
1230
1231   SIMIX_simcall_push(simcall->issuer);
1232   return simcall->comm_get_dst_proc.result;
1233 }
1234
1235 #ifdef HAVE_LATENCY_BOUND_TRACKING
1236 int simcall_comm_is_latency_bounded(smx_action_t comm)
1237 {
1238   smx_simcall_t simcall = SIMIX_simcall_mine();
1239
1240   simcall->call = SIMCALL_COMM_IS_LATENCY_BOUNDED;
1241   simcall->comm_is_latency_bounded.comm = comm;
1242   if(MC_IS_ENABLED) /* Initialize result to a default value for snapshot comparison done during simcall */
1243     simcall->comm_is_latency_bounded.result = -1;
1244
1245   SIMIX_simcall_push(simcall->issuer);
1246   return simcall->comm_is_latency_bounded.result;
1247 }
1248 #endif
1249 /**
1250  * \ingroup simix_synchro_management
1251  *
1252  */
1253 smx_mutex_t simcall_mutex_init(void)
1254 {
1255   if(!simix_global) {
1256     fprintf(stderr,"You must run MSG_init or gras_init before using MSG or GRAS\n"); // I would have loved using xbt_die but I can't since it is not initialized yet... :)
1257     abort();
1258   }
1259   smx_simcall_t simcall = SIMIX_simcall_mine();
1260
1261   simcall->call = SIMCALL_MUTEX_INIT;
1262   if(MC_IS_ENABLED) /* Initialize result to NULL for snapshot comparison done during simcall */
1263     simcall->mutex_init.result = NULL;
1264
1265   SIMIX_simcall_push(simcall->issuer);
1266   return simcall->mutex_init.result;
1267 }
1268 /**
1269  * \ingroup simix_synchro_management
1270  *
1271  */
1272 void simcall_mutex_destroy(smx_mutex_t mutex)
1273 {
1274   smx_simcall_t simcall = SIMIX_simcall_mine();
1275
1276   simcall->call = SIMCALL_MUTEX_DESTROY;
1277   simcall->mutex_destroy.mutex = mutex;
1278
1279   SIMIX_simcall_push(simcall->issuer);
1280 }
1281 /**
1282  * \ingroup simix_synchro_management
1283  *
1284  */
1285 void simcall_mutex_lock(smx_mutex_t mutex)
1286 {
1287   smx_simcall_t simcall = SIMIX_simcall_mine();
1288
1289   simcall->call = SIMCALL_MUTEX_LOCK;
1290   simcall->mutex_lock.mutex = mutex;
1291
1292   SIMIX_simcall_push(simcall->issuer);
1293 }
1294 /**
1295  * \ingroup simix_synchro_management
1296  *
1297  */
1298 int simcall_mutex_trylock(smx_mutex_t mutex)
1299 {
1300   smx_simcall_t simcall = SIMIX_simcall_mine();
1301
1302   simcall->call = SIMCALL_MUTEX_TRYLOCK;
1303   simcall->mutex_trylock.mutex = mutex;
1304   if(MC_IS_ENABLED) /* Initialize result to a default value for snapshot comparison done during simcall */
1305     simcall->mutex_trylock.result = -1;
1306
1307   SIMIX_simcall_push(simcall->issuer);
1308   return simcall->mutex_trylock.result;
1309 }
1310 /**
1311  * \ingroup simix_synchro_management
1312  *
1313  */
1314 void simcall_mutex_unlock(smx_mutex_t mutex)
1315 {
1316   smx_simcall_t simcall = SIMIX_simcall_mine();
1317
1318   simcall->call = SIMCALL_MUTEX_UNLOCK;
1319   simcall->mutex_unlock.mutex = mutex;
1320
1321   SIMIX_simcall_push(simcall->issuer);
1322 }
1323 /**
1324  * \ingroup simix_synchro_management
1325  *
1326  */
1327 smx_cond_t simcall_cond_init(void)
1328 {
1329   smx_simcall_t simcall = SIMIX_simcall_mine();
1330
1331   simcall->call = SIMCALL_COND_INIT;
1332   if(MC_IS_ENABLED) /* Initialize result to NULL for snapshot comparison done during simcall */
1333     simcall->cond_init.result = NULL;
1334
1335   SIMIX_simcall_push(simcall->issuer);
1336   return simcall->cond_init.result;
1337 }
1338 /**
1339  * \ingroup simix_synchro_management
1340  *
1341  */
1342 void simcall_cond_destroy(smx_cond_t cond)
1343 {
1344   smx_simcall_t simcall = SIMIX_simcall_mine();
1345
1346   simcall->call = SIMCALL_COND_DESTROY;
1347   simcall->cond_destroy.cond = cond;
1348
1349   SIMIX_simcall_push(simcall->issuer);
1350 }
1351 /**
1352  * \ingroup simix_synchro_management
1353  *
1354  */
1355 void simcall_cond_signal(smx_cond_t cond)
1356 {
1357   smx_simcall_t simcall = SIMIX_simcall_mine();
1358
1359   simcall->call = SIMCALL_COND_SIGNAL;
1360   simcall->cond_signal.cond = cond;
1361
1362   SIMIX_simcall_push(simcall->issuer);
1363 }
1364 /**
1365  * \ingroup simix_synchro_management
1366  *
1367  */
1368 void simcall_cond_wait(smx_cond_t cond, smx_mutex_t mutex)
1369 {
1370   smx_simcall_t simcall = SIMIX_simcall_mine();
1371
1372   simcall->call = SIMCALL_COND_WAIT;
1373   simcall->cond_wait.cond = cond;
1374   simcall->cond_wait.mutex = mutex;
1375
1376   SIMIX_simcall_push(simcall->issuer);
1377 }
1378 /**
1379  * \ingroup simix_synchro_management
1380  *
1381  */
1382 void simcall_cond_wait_timeout(smx_cond_t cond,
1383                                  smx_mutex_t mutex,
1384                                  double timeout)
1385 {
1386   xbt_assert(isfinite(timeout), "timeout is not finite!");
1387   
1388   smx_simcall_t simcall = SIMIX_simcall_mine();
1389
1390   simcall->call = SIMCALL_COND_WAIT_TIMEOUT;
1391   simcall->cond_wait_timeout.cond = cond;
1392   simcall->cond_wait_timeout.mutex = mutex;
1393   simcall->cond_wait_timeout.timeout = timeout;
1394
1395   SIMIX_simcall_push(simcall->issuer);
1396 }
1397 /**
1398  * \ingroup simix_synchro_management
1399  *
1400  */
1401 void simcall_cond_broadcast(smx_cond_t cond)
1402 {
1403   smx_simcall_t simcall = SIMIX_simcall_mine();
1404
1405   simcall->call = SIMCALL_COND_BROADCAST;
1406   simcall->cond_broadcast.cond = cond;
1407
1408   SIMIX_simcall_push(simcall->issuer);
1409 }
1410 /**
1411  * \ingroup simix_synchro_management
1412  *
1413  */
1414 smx_sem_t simcall_sem_init(int capacity)
1415 {
1416   smx_simcall_t simcall = SIMIX_simcall_mine();
1417
1418   simcall->call = SIMCALL_SEM_INIT;
1419   simcall->sem_init.capacity = capacity;
1420   if(MC_IS_ENABLED) /* Initialize result to NULL for snapshot comparison done during simcall */
1421     simcall->sem_init.result = NULL;
1422
1423   SIMIX_simcall_push(simcall->issuer);
1424   return simcall->sem_init.result;
1425 }
1426 /**
1427  * \ingroup simix_synchro_management
1428  *
1429  */
1430 void simcall_sem_destroy(smx_sem_t sem)
1431 {
1432   smx_simcall_t simcall = SIMIX_simcall_mine();
1433
1434   simcall->call = SIMCALL_SEM_DESTROY;
1435   simcall->sem_destroy.sem = sem;
1436
1437   SIMIX_simcall_push(simcall->issuer);
1438 }
1439 /**
1440  * \ingroup simix_synchro_management
1441  *
1442  */
1443 void simcall_sem_release(smx_sem_t sem)
1444 {
1445   smx_simcall_t simcall = SIMIX_simcall_mine();
1446
1447   simcall->call = SIMCALL_SEM_RELEASE;
1448   simcall->sem_release.sem = sem;
1449
1450   SIMIX_simcall_push(simcall->issuer);
1451 }
1452 /**
1453  * \ingroup simix_synchro_management
1454  *
1455  */
1456 int simcall_sem_would_block(smx_sem_t sem)
1457 {
1458   smx_simcall_t simcall = SIMIX_simcall_mine();
1459
1460   simcall->call = SIMCALL_SEM_WOULD_BLOCK;
1461   simcall->sem_would_block.sem = sem;
1462   if(MC_IS_ENABLED) /* Initialize result to a default value for snapshot comparison done during simcall */
1463     simcall->sem_would_block.result = -1;
1464
1465   SIMIX_simcall_push(simcall->issuer);
1466   return simcall->sem_would_block.result;
1467 }
1468 /**
1469  * \ingroup simix_synchro_management
1470  *
1471  */
1472 void simcall_sem_acquire(smx_sem_t sem)
1473 {
1474   smx_simcall_t simcall = SIMIX_simcall_mine();
1475
1476   simcall->call = SIMCALL_SEM_ACQUIRE;
1477   simcall->sem_acquire.sem = sem;
1478
1479   SIMIX_simcall_push(simcall->issuer);
1480 }
1481 /**
1482  * \ingroup simix_synchro_management
1483  *
1484  */
1485 void simcall_sem_acquire_timeout(smx_sem_t sem, double timeout)
1486 {
1487   xbt_assert(isfinite(timeout), "timeout is not finite!");
1488   
1489   smx_simcall_t simcall = SIMIX_simcall_mine();
1490
1491   simcall->call = SIMCALL_SEM_ACQUIRE_TIMEOUT;
1492   simcall->sem_acquire_timeout.sem = sem;
1493   simcall->sem_acquire_timeout.timeout = timeout;
1494
1495   SIMIX_simcall_push(simcall->issuer);
1496 }
1497 /**
1498  * \ingroup simix_synchro_management
1499  *
1500  */
1501 int simcall_sem_get_capacity(smx_sem_t sem)
1502 {
1503   smx_simcall_t simcall = SIMIX_simcall_mine();
1504
1505   simcall->call = SIMCALL_SEM_GET_CAPACITY;
1506   simcall->sem_get_capacity.sem = sem;
1507   if(MC_IS_ENABLED) /* Initialize result to a default value for snapshot comparison done during simcall */
1508     simcall->sem_get_capacity.result = -1;
1509
1510   SIMIX_simcall_push(simcall->issuer);
1511   return simcall->sem_get_capacity.result;
1512 }
1513 /**
1514  * \ingroup simix_file_management
1515  *
1516  */
1517 double simcall_file_read(void* ptr, size_t size, size_t nmemb, smx_file_t stream)
1518 {
1519   smx_simcall_t simcall = SIMIX_simcall_mine();
1520
1521   simcall->call = SIMCALL_FILE_READ;
1522   simcall->file_read.ptr = ptr;
1523   simcall->file_read.size = size;
1524   simcall->file_read.nmemb = nmemb;
1525   simcall->file_read.stream = stream;
1526   if(MC_IS_ENABLED) /* Initialize result to a default value for snapshot comparison done during simcall */
1527     simcall->file_read.result = 0.0;
1528   SIMIX_simcall_push(simcall->issuer);
1529
1530   return simcall->file_read.result;
1531 }
1532 /**
1533  * \ingroup simix_file_management
1534  *
1535  */
1536 size_t simcall_file_write(const void* ptr, size_t size, size_t nmemb, smx_file_t stream)
1537 {
1538   smx_simcall_t simcall = SIMIX_simcall_mine();
1539
1540   simcall->call = SIMCALL_FILE_WRITE;
1541   simcall->file_write.ptr = ptr;
1542   simcall->file_write.size = size;
1543   simcall->file_write.nmemb = nmemb;
1544   simcall->file_write.stream = stream;
1545   if(MC_IS_ENABLED) /* Initialize result to a default value for snapshot comparison done during simcall */
1546     simcall->file_write.result = 0;
1547   SIMIX_simcall_push(simcall->issuer);
1548
1549   return simcall->file_write.result;
1550 }
1551 /**
1552  * \ingroup simix_file_management
1553  * \brief
1554  */
1555 smx_file_t simcall_file_open(const char* mount, const char* path, const char* mode)
1556 {
1557   smx_simcall_t simcall = SIMIX_simcall_mine();
1558
1559   simcall->call = SIMCALL_FILE_OPEN;
1560   simcall->file_open.mount = mount;
1561   simcall->file_open.path = path;
1562   simcall->file_open.mode = mode;
1563   if(MC_IS_ENABLED) /* Initialize result to NULL for snapshot comparison done during simcall */
1564     simcall->file_open.result = NULL;
1565   SIMIX_simcall_push(simcall->issuer);
1566
1567   return simcall->file_open.result;
1568 }
1569 /**
1570  * \ingroup simix_file_management
1571  *
1572  */
1573 int simcall_file_close(smx_file_t fp)
1574 {
1575   smx_simcall_t simcall = SIMIX_simcall_mine();
1576
1577   simcall->call = SIMCALL_FILE_CLOSE;
1578   simcall->file_close.fp = fp;
1579   if(MC_IS_ENABLED) /* Initialize result to a default value for snapshot comparison done during simcall */
1580     simcall->file_close.result = -1;
1581   SIMIX_simcall_push(simcall->issuer);
1582
1583   return simcall->file_close.result;
1584 }
1585 /**
1586  * \ingroup simix_file_management
1587  *
1588  */
1589 int simcall_file_stat(smx_file_t fd, s_file_stat_t *buf)
1590 {
1591   smx_simcall_t simcall = SIMIX_simcall_mine();
1592   simcall->call = SIMCALL_FILE_STAT;
1593   simcall->file_stat.fd = fd;
1594   if(MC_IS_ENABLED) /* Initialize result to a default value for snapshot comparison done during simcall */
1595     simcall->file_stat.result = -1;
1596
1597   SIMIX_simcall_push(simcall->issuer);
1598
1599   *buf = simcall->file_stat.buf;
1600
1601   return simcall->file_stat.result;
1602 }
1603
1604 /**
1605  * \ingroup simix_file_management
1606  *
1607  */
1608 int simcall_file_unlink(smx_file_t fd)
1609 {
1610   smx_simcall_t simcall = SIMIX_simcall_mine();
1611   simcall->call = SIMCALL_FILE_UNLINK;
1612   simcall->file_unlink.fd = fd;
1613   if(MC_IS_ENABLED) /* Initialize result to a default value for snapshot comparison done during simcall */
1614     simcall->file_unlink.result = -1;
1615
1616   SIMIX_simcall_push(simcall->issuer);
1617
1618   return simcall->file_unlink.result;
1619 }
1620
1621 /**
1622  * \ingroup simix_file_management
1623  *
1624  */
1625 xbt_dict_t simcall_file_ls(const char* mount, const char* path)
1626 {
1627   smx_simcall_t simcall = SIMIX_simcall_mine();
1628   simcall->call = SIMCALL_FILE_LS;
1629   simcall->file_ls.mount = mount;
1630   simcall->file_ls.path = path;
1631   if(MC_IS_ENABLED) /* Initialize result to a default value for snapshot comparison done during simcall */
1632     simcall->file_ls.result = NULL;
1633
1634   SIMIX_simcall_push(simcall->issuer);
1635
1636   return simcall->file_ls.result;
1637 }
1638
1639 /* ************************************************************************** */
1640
1641 /** @brief returns a printable string representing a simcall */
1642 const char *SIMIX_simcall_name(e_smx_simcall_t kind) {
1643   return simcall_names[kind];
1644 }