Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make SimGrid compile again :)
[simgrid.git] / src / simix / smx_user.c
1 /* smx_user.c - public interface to simix                                   */
2
3 /* Copyright (c) 2010-2012. 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
8 #include "smx_private.h"
9 #include "mc/mc.h"
10 #include "xbt/ex.h"
11 #include <math.h>         /* isfinite() */
12
13 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix);
14
15 static const char* simcall_names[] = {
16 #undef SIMCALL_ENUM_ELEMENT
17 #define SIMCALL_ENUM_ELEMENT(x,y) #x /* generate strings from the enumeration values */
18 SIMCALL_LIST
19 #undef SIMCALL_ENUM_ELEMENT
20 };
21
22 /**
23  * \ingroup simix_host_management
24  * \brief Returns a host given its name.
25  *
26  * \param name The name of the host to get
27  * \return The corresponding host
28  */
29 smx_host_t simcall_host_get_by_name(const char *name)
30 {
31   smx_simcall_t simcall = SIMIX_simcall_mine();
32
33   simcall->call = SIMCALL_HOST_GET_BY_NAME;
34   simcall->host_get_by_name.name = name;
35   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
36     simcall->host_get_by_name.result = NULL;
37   SIMIX_simcall_push(simcall->issuer);
38   return simcall->host_get_by_name.result;
39 }
40
41 /**
42  * \ingroup simix_host_management
43  * \brief Returns the name of a host.
44  *
45  * \param host A SIMIX host
46  * \return The name of this host
47  */
48 const char* simcall_host_get_name(smx_host_t host)
49 {
50   smx_simcall_t simcall = SIMIX_simcall_mine();
51
52   simcall->call = SIMCALL_HOST_GET_NAME;
53   simcall->host_get_name.host = host;
54   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
55     simcall->host_get_name.result = NULL;
56   SIMIX_simcall_push(simcall->issuer);
57   return simcall->host_get_name.result;
58 }
59
60 /**
61  * \ingroup simix_host_management
62  * \brief Returns a dict of the properties assigned to a host.
63  *
64  * \param host A host
65  * \return The properties of this host
66  */
67 xbt_dict_t simcall_host_get_properties(smx_host_t host)
68 {
69   smx_simcall_t simcall = SIMIX_simcall_mine();
70
71   simcall->call = SIMCALL_HOST_GET_PROPERTIES;
72   simcall->host_get_properties.host = host;
73   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
74     simcall->host_get_properties.result = NULL;
75   SIMIX_simcall_push(simcall->issuer);
76   return simcall->host_get_properties.result;
77 }
78
79 /**
80  * \ingroup simix_host_management
81  * \brief Returns a dict of the properties assigned to a router or AS.
82  *
83  * \param name The name of the router or AS
84  * \return The properties
85  */
86 xbt_dict_t simcall_asr_get_properties(const char *name)
87 {
88   smx_simcall_t simcall = SIMIX_simcall_mine();
89
90   simcall->call = SIMCALL_ASR_GET_PROPERTIES;
91   simcall->asr_get_properties.name = name;
92   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
93     simcall->asr_get_properties.result = NULL;
94   SIMIX_simcall_push(simcall->issuer);
95   return simcall->asr_get_properties.result;
96 }
97
98
99 /**
100  * \ingroup simix_host_management
101  * \brief Returns the speed of the processor.
102  *
103  * The speed returned does not take into account the current load on the machine.
104  * \param host A SIMIX host
105  * \return The speed of this host (in Mflop/s)
106  */
107 double simcall_host_get_speed(smx_host_t host)
108 {
109   smx_simcall_t simcall = SIMIX_simcall_mine();
110
111   simcall->call = SIMCALL_HOST_GET_SPEED;
112   simcall->host_get_speed.host = host;
113   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
114     simcall->host_get_speed.result = 0.0;
115   SIMIX_simcall_push(simcall->issuer);
116   return simcall->host_get_speed.result;
117 }
118
119 /**
120  * \ingroup simix_host_management
121  * \brief Returns the available speed of the processor.
122  *
123  * \return Speed currently available (in Mflop/s)
124  */
125 double simcall_host_get_available_speed(smx_host_t host)
126 {
127   smx_simcall_t simcall = SIMIX_simcall_mine();
128
129   simcall->call = SIMCALL_HOST_GET_AVAILABLE_SPEED;
130   simcall->host_get_available_speed.host = host;
131   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
132     simcall->host_get_available_speed.result = 0.0;
133   SIMIX_simcall_push(simcall->issuer);
134   return simcall->host_get_available_speed.result;
135 }
136
137 /**
138  * \ingroup simix_host_management
139  * \brief Returns the state of a host.
140  *
141  * Two states are possible: 1 if the host is active or 0 if it has crashed.
142  * \param host A SIMIX host
143  * \return 1 if the host is available, 0 otherwise
144  */
145 int simcall_host_get_state(smx_host_t host)
146 {
147   smx_simcall_t simcall = SIMIX_simcall_mine();
148
149   simcall->call = SIMCALL_HOST_GET_STATE;
150   simcall->host_get_state.host = host;
151   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
152     simcall->host_get_state.result = -1;
153   SIMIX_simcall_push(simcall->issuer);
154   return simcall->host_get_state.result;
155 }
156
157 /**
158  * \ingroup simix_host_management
159  * \brief Returns the user data associated to a host.
160  *
161  * \param host SIMIX host
162  * \return the user data of this host
163  */
164 void* simcall_host_get_data(smx_host_t host)
165 {
166   smx_simcall_t simcall = SIMIX_simcall_mine();
167
168   simcall->call = SIMCALL_HOST_GET_DATA;
169   simcall->host_get_data.host = host;
170   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
171     simcall->host_get_data.result = NULL;
172   SIMIX_simcall_push(simcall->issuer);
173   return simcall->host_get_data.result;
174 }
175
176 /**
177  * \ingroup simix_host_management
178  * \brief Sets the user data associated to a host.
179  *
180  * The host must not have previous user data associated to it.
181  * \param host A SIMIX host
182  * \param data The user data to set
183  */
184 void simcall_host_set_data(smx_host_t host, void *data)
185 {
186   smx_simcall_t simcall = SIMIX_simcall_mine();
187
188   simcall->call = SIMCALL_HOST_SET_DATA;
189   simcall->host_set_data.host = host;
190   simcall->host_set_data.data = data;
191   SIMIX_simcall_push(simcall->issuer);
192 }
193
194 /**
195  * \ingroup simix_host_management
196  * \brief Creates an action that executes some computation of an host.
197  *
198  * This function creates a SURF action and allocates the data necessary
199  * to create the SIMIX action. It can raise a host_error exception if the host crashed.
200  *
201  * \param name Name of the execution action to create
202  * \param host SIMIX host where the action will be executed
203  * \param computation_amount amount Computation amount (in bytes)
204  * \param priority computation priority
205  * \return A new SIMIX execution action
206  */
207
208 smx_action_t simcall_host_execute(const char *name, smx_host_t host,
209                                     double computation_amount,
210                                     double priority)
211 {
212   /* checking for infinite values */
213   xbt_assert(isfinite(computation_amount), "computation_amount is not finite!");
214   xbt_assert(isfinite(priority), "priority is not finite!");
215   
216   smx_simcall_t simcall = SIMIX_simcall_mine();
217
218   simcall->call = SIMCALL_HOST_EXECUTE;
219   simcall->host_execute.name = name;
220   simcall->host_execute.host = host;
221   simcall->host_execute.computation_amount = computation_amount;
222   simcall->host_execute.priority = priority;
223
224   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
225     simcall->host_execute.result = NULL;
226
227   SIMIX_simcall(SIMCALL_HOST_EXECUTE, PTR(name), PTR(host), DOUBLE(computation_amount), DOUBLE(priority));
228
229   return simcall->host_execute.result;
230 }
231
232 /**
233  * \ingroup simix_host_management
234  * \brief Creates an action that may involve parallel computation on
235  * several hosts and communication between them.
236  *
237  * \param name Name of the execution action to create
238  * \param host_nb Number of hosts where the action will be executed
239  * \param host_list Array (of size host_nb) of hosts where the action will be executed
240  * \param computation_amount Array (of size host_nb) of computation amount of hosts (in bytes)
241  * \param communication_amount Array (of size host_nb * host_nb) representing the communication
242  * amount between each pair of hosts
243  * \param amount the SURF action amount
244  * \param rate the SURF action rate
245  * \return A new SIMIX execution action
246  */
247 smx_action_t simcall_host_parallel_execute(const char *name,
248                                          int host_nb,
249                                          smx_host_t *host_list,
250                                          double *computation_amount,
251                                          double *communication_amount,
252                                          double amount,
253                                          double rate)
254 {
255   int i,j;
256   /* checking for infinite values */
257   for (i = 0 ; i < host_nb ; ++i) {
258      xbt_assert(isfinite(computation_amount[i]), "computation_amount[%d] is not finite!", i);
259      for (j = 0 ; j < host_nb ; ++j) {
260         xbt_assert(isfinite(communication_amount[i + host_nb * j]), 
261              "communication_amount[%d+%d*%d] is not finite!", i, host_nb, j);
262      }   
263   }   
264  
265   xbt_assert(isfinite(amount), "amount is not finite!");
266   xbt_assert(isfinite(rate), "rate is not finite!");
267   
268   smx_simcall_t simcall = SIMIX_simcall_mine();
269
270   simcall->call = SIMCALL_HOST_PARALLEL_EXECUTE;
271   simcall->host_parallel_execute.name = name;
272   simcall->host_parallel_execute.host_nb = host_nb;
273   simcall->host_parallel_execute.host_list = host_list;
274   simcall->host_parallel_execute.computation_amount = computation_amount;
275   simcall->host_parallel_execute.communication_amount = communication_amount;
276   simcall->host_parallel_execute.amount = amount;
277   simcall->host_parallel_execute.rate = rate;
278   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
279     simcall->host_parallel_execute.result = NULL;
280   SIMIX_simcall_push(simcall->issuer);
281   return simcall->host_parallel_execute.result;
282 }
283
284 /**
285  * \ingroup simix_host_management
286  * \brief Destroys an execution action.
287  *
288  * Destroys an action, freing its memory. This function cannot be called if there are a conditional waiting for it.
289  * \param execution The execution action to destroy
290  */
291 void simcall_host_execution_destroy(smx_action_t execution)
292 {
293   smx_simcall_t simcall = SIMIX_simcall_mine();
294
295   simcall->call = SIMCALL_HOST_EXECUTION_DESTROY;
296   simcall->host_execution_destroy.execution = execution;
297   SIMIX_simcall_push(simcall->issuer);
298 }
299
300 /**
301  * \ingroup simix_host_management
302  * \brief Cancels an execution action.
303  *
304  * This functions stops the execution. It calls a surf function.
305  * \param execution The execution action to cancel
306  */
307 void simcall_host_execution_cancel(smx_action_t execution)
308 {
309   smx_simcall_t simcall = SIMIX_simcall_mine();
310
311   simcall->call = SIMCALL_HOST_EXECUTION_CANCEL;
312   simcall->host_execution_cancel.execution = execution;
313   SIMIX_simcall_push(simcall->issuer);
314 }
315
316 /**
317  * \ingroup simix_host_management
318  * \brief Returns how much of an execution action remains to be done.
319  *
320  * \param execution The execution action
321  * \return The remaining amount
322  */
323 double simcall_host_execution_get_remains(smx_action_t execution)
324 {
325   smx_simcall_t simcall = SIMIX_simcall_mine();
326
327   simcall->call = SIMCALL_HOST_EXECUTION_GET_REMAINS;
328   simcall->host_execution_get_remains.execution = execution;
329   if(MC_is_active()) /* Initializeialize result to a default value for snapshot comparison done during simcall */
330     simcall->host_execution_get_remains.result = 0.0;
331   SIMIX_simcall_push(simcall->issuer);
332   return simcall->host_execution_get_remains.result;
333 }
334
335 /**
336  * \ingroup simix_host_management
337  * \brief Returns the state of an execution action.
338  *
339  * \param execution The execution action
340  * \return The state
341  */
342 e_smx_state_t simcall_host_execution_get_state(smx_action_t execution)
343 {
344   smx_simcall_t simcall = SIMIX_simcall_mine();
345
346   simcall->call = SIMCALL_HOST_EXECUTION_GET_STATE;
347   simcall->host_execution_get_state.execution = execution;
348   simcall->host_execution_get_state.result = -1;
349   SIMIX_simcall_push(simcall->issuer);
350   return simcall->host_execution_get_state.result;
351 }
352
353 /**
354  * \ingroup simix_host_management
355  * \brief Changes the priority of an execution action.
356  *
357  * This functions changes the priority only. It calls a surf function.
358  * \param execution The execution action
359  * \param priority The new priority
360  */
361 void simcall_host_execution_set_priority(smx_action_t execution, double priority)
362 {
363   /* checking for infinite values */
364   xbt_assert(isfinite(priority), "priority is not finite!");
365   
366   smx_simcall_t simcall = SIMIX_simcall_mine();
367
368   simcall->call = SIMCALL_HOST_EXECUTION_SET_PRIORITY;
369   simcall->host_execution_set_priority.execution = execution;
370   simcall->host_execution_set_priority.priority = priority;
371   SIMIX_simcall_push(simcall->issuer);
372 }
373
374 /**
375  * \ingroup simix_host_management
376  * \brief Waits for the completion of an execution action and destroy it.
377  *
378  * \param execution The execution action
379  */
380 e_smx_state_t simcall_host_execution_wait(smx_action_t execution)
381 {
382   smx_simcall_t simcall = SIMIX_simcall_mine();
383
384   simcall->call = SIMCALL_HOST_EXECUTION_WAIT;
385   simcall->host_execution_wait.execution = execution;
386   simcall->host_execution_wait.simcall = simcall;
387
388   SIMIX_simcall(SIMCALL_HOST_EXECUTION_WAIT, PTR(simcall), PTR(execution));
389
390   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
391     simcall->host_execution_wait.result = -1;
392
393   return simcall->host_execution_wait.result;
394 }
395
396 /**
397  * \ingroup simix_process_management
398  * \brief Creates and runs a new SIMIX process.
399  *
400  * The structure and the corresponding thread are created and put in the list of ready processes.
401  *
402  * \param process the process created will be stored in this pointer
403  * \param name a name for the process. It is for user-level information and can be NULL.
404  * \param code the main function of the process
405  * \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.
406  * It can be retrieved with the function \ref simcall_process_get_data.
407  * \param hostname name of the host where the new agent is executed.
408  * \param kill_time time when the process is killed
409  * \param argc first argument passed to \a code
410  * \param argv second argument passed to \a code
411  * \param properties the properties of the process
412  * \param auto_restart either it is autorestarting or not.
413  */
414 void simcall_process_create(smx_process_t *process, const char *name,
415                               xbt_main_func_t code,
416                               void *data,
417                               const char *hostname,
418                               double kill_time,
419                               int argc, char **argv,
420                               xbt_dict_t properties,
421                               int auto_restart)
422 {
423   smx_simcall_t simcall = SIMIX_simcall_mine();
424
425   simcall->call = SIMCALL_PROCESS_CREATE;
426   simcall->process_create.process = process;
427   simcall->process_create.name = name;
428   simcall->process_create.code = code;
429   simcall->process_create.data = data;
430   simcall->process_create.hostname = hostname;
431   simcall->process_create.kill_time = kill_time;
432   simcall->process_create.argc = argc;
433   simcall->process_create.argv = argv;
434   simcall->process_create.properties = properties;
435   simcall->process_create.auto_restart = auto_restart;
436   SIMIX_simcall_push(simcall->issuer);
437 }
438
439 /**
440  * \ingroup simix_process_management
441  * \brief Kills a SIMIX process.
442  *
443  * This function simply kills a  process.
444  *
445  * \param process poor victim
446  */
447 void simcall_process_kill(smx_process_t process)
448 {
449   smx_simcall_t simcall = SIMIX_simcall_mine();
450
451   simcall->call = SIMCALL_PROCESS_KILL;
452   simcall->process_kill.process = process;
453   SIMIX_simcall_push(simcall->issuer);
454 }
455
456 /**
457  * \ingroup simix_process_management
458  * \brief Kills all SIMIX processes.
459  */
460 void simcall_process_killall(void)
461 {
462   smx_simcall_t simcall = SIMIX_simcall_mine();
463
464   simcall->call = SIMCALL_PROCESS_KILLALL;
465   SIMIX_simcall_push(simcall->issuer);
466 }
467
468 /**
469  * \ingroup simix_process_management
470  * \brief Cleans up a SIMIX process.
471  * \param process poor victim (must have already been killed)
472  */
473 void simcall_process_cleanup(smx_process_t process)
474 {
475   smx_simcall_t simcall = SIMIX_simcall_mine();
476
477   simcall->call = SIMCALL_PROCESS_CLEANUP;
478   simcall->process_cleanup.process = process;
479   SIMIX_simcall_push(simcall->issuer);
480 }
481
482 /**
483  * \ingroup simix_process_management
484  * \brief Migrates an agent to another location.
485  *
486  * This function changes the value of the host on which \a process is running.
487  *
488  * \param process the process to migrate
489  * \param dest name of the new host
490  */
491 void simcall_process_change_host(smx_process_t process, smx_host_t dest)
492 {
493   smx_simcall_t simcall = SIMIX_simcall_mine();
494
495   simcall->call = SIMCALL_PROCESS_CHANGE_HOST;
496   simcall->process_change_host.process = process;
497   simcall->process_change_host.dest = dest;
498   SIMIX_simcall_push(simcall->issuer);
499 }
500
501 /**
502  * \ingroup simix_process_management
503  * \brief Suspends a process.
504  *
505  * This function suspends the process by suspending the action
506  * it was waiting for completion.
507  *
508  * \param process a SIMIX process
509  */
510 void simcall_process_suspend(smx_process_t process)
511 {
512   xbt_assert(process, "Invalid parameters");
513
514   smx_simcall_t simcall = SIMIX_simcall_mine();
515
516   simcall->call = SIMCALL_PROCESS_SUSPEND;
517   simcall->process_suspend.process = process;
518   SIMIX_simcall_push(simcall->issuer);
519 }
520
521 /**
522  * \ingroup simix_process_management
523  * \brief Resumes a suspended process.
524  *
525  * This function resumes a suspended process by resuming the action
526  * it was waiting for completion.
527  *
528  * \param process a SIMIX process
529  */
530 void simcall_process_resume(smx_process_t process)
531 {
532   smx_simcall_t simcall = SIMIX_simcall_mine();
533
534   simcall->call = SIMCALL_PROCESS_RESUME;
535   simcall->process_resume.process = process;
536   SIMIX_simcall_push(simcall->issuer);
537 }
538
539 /**
540  * \ingroup simix_process_management
541  * \brief Returns the amount of SIMIX processes in the system
542  *
543  * Maestro internal process is not counted, only user code processes are
544  */
545 int simcall_process_count(void)
546 {
547   smx_simcall_t simcall = SIMIX_simcall_mine();
548
549   simcall->call = SIMCALL_PROCESS_COUNT;
550   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
551     simcall->process_count.result = -1;
552   SIMIX_simcall_push(simcall->issuer);
553   return simcall->process_count.result;
554 }
555
556 /**
557  * \ingroup simix_process_management
558  * \brief Return the user data of a #smx_process_t.
559  * \param process a SIMIX process
560  * \return the user data of this process
561  */
562 void* simcall_process_get_data(smx_process_t process)
563 {
564   if (process == SIMIX_process_self()) {
565     /* avoid a simcall if this function is called by the process itself */
566     return SIMIX_process_get_data(process);
567   }
568
569   smx_simcall_t simcall = SIMIX_simcall_mine();
570
571   simcall->call = SIMCALL_PROCESS_GET_DATA;
572   simcall->process_get_data.process = process;
573   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
574     simcall->process_get_data.result = NULL;
575   SIMIX_simcall_push(simcall->issuer);
576   return simcall->process_get_data.result;
577 }
578
579 /**
580  * \ingroup simix_process_management
581  * \brief Set the user data of a #smx_process_t.
582  *
583  * This functions sets the user data associated to \a process.
584  * \param process SIMIX process
585  * \param data User data
586  */
587 void simcall_process_set_data(smx_process_t process, void *data)
588 {
589   if (process == SIMIX_process_self()) {
590     /* avoid a simcall if this function is called by the process itself */
591     SIMIX_process_self_set_data(process, data);
592   }
593   else {
594
595     smx_simcall_t simcall = SIMIX_simcall_mine();
596
597     simcall->call = SIMCALL_PROCESS_SET_DATA;
598     simcall->process_set_data.process = process;
599     simcall->process_set_data.data = data;
600     SIMIX_simcall_push(simcall->issuer);
601   }
602 }
603
604 /**
605  * \ingroup simix_process_management
606  * \brief Set the kill time of a process.
607  * \param process a process
608  * \param kill_time a double
609  */
610 void simcall_process_set_kill_time(smx_process_t process, double kill_time)
611 {
612
613   if (kill_time > SIMIX_get_clock()) {
614     if (simix_global->kill_process_function) {
615       XBT_DEBUG("Set kill time %f for process %s(%s)",kill_time, process->name,
616           process->smx_host->name);
617       SIMIX_timer_set(kill_time, simix_global->kill_process_function, process);
618     }
619   }
620 }
621
622 /**
623  * \ingroup simix_process_management
624  * \brief Return the location on which an agent is running.
625  *
626  * This functions returns the smx_host_t corresponding to the location on which
627  * \a process is running.
628  * \param process SIMIX process
629  * \return SIMIX host
630  */
631 smx_host_t simcall_process_get_host(smx_process_t process)
632 {
633   smx_simcall_t simcall = SIMIX_simcall_mine();
634
635   simcall->call = SIMCALL_PROCESS_GET_HOST;
636   simcall->process_get_host.process = process;
637   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
638     simcall->process_get_host.result = NULL;
639   SIMIX_simcall_push(simcall->issuer);
640   return simcall->process_get_host.result;
641 }
642
643 /**
644  * \ingroup simix_process_management
645  * \brief Return the name of an agent.
646  *
647  * This functions checks whether \a process is a valid pointer or not and return its name.
648  * \param process SIMIX process
649  * \return The process name
650  */
651 const char* simcall_process_get_name(smx_process_t process)
652 {
653   if (process == SIMIX_process_self()) {
654     /* avoid a simcall if this function is called by the process itself */
655     return process->name;
656   }
657
658   smx_simcall_t simcall = SIMIX_simcall_mine();
659
660   simcall->call = SIMCALL_PROCESS_GET_NAME;
661   simcall->process_get_name.process = process;
662   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
663     simcall->process_get_name.result = NULL;
664   SIMIX_simcall_push(simcall->issuer);
665   return simcall->process_get_name.result;
666 }
667
668 /**
669  * \ingroup simix_process_management
670  * \brief Returns true if the process is suspended .
671  *
672  * This checks whether a process is suspended or not by inspecting the task on which it was waiting for the completion.
673  * \param process SIMIX process
674  * \return 1, if the process is suspended, else 0.
675  */
676 int simcall_process_is_suspended(smx_process_t process)
677 {
678   smx_simcall_t simcall = SIMIX_simcall_mine();
679
680   simcall->call = SIMCALL_PROCESS_IS_SUSPENDED;
681   simcall->process_is_suspended.process = process;
682   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
683     simcall->process_is_suspended.result = -1;
684   SIMIX_simcall_push(simcall->issuer);
685   return simcall->process_is_suspended.result;
686 }
687
688 /**
689  * \ingroup simix_process_management
690  * \brief Return the properties
691  *
692  * This functions returns the properties associated with this process
693  */
694 xbt_dict_t simcall_process_get_properties(smx_process_t process)
695 {
696   smx_simcall_t simcall = SIMIX_simcall_mine();
697
698   simcall->call = SIMCALL_PROCESS_GET_PROPERTIES;
699   simcall->process_get_properties.process = process;
700   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
701     simcall->process_get_properties.result = NULL;
702   SIMIX_simcall_push(simcall->issuer);
703   return simcall->process_get_properties.result;
704 }
705 /**
706  * \ingroup simix_process_management
707  * \brief Add an on_exit function
708  * Add an on_exit function which will be executed when the process exits/is killed.
709  */
710 XBT_PUBLIC(void) simcall_process_on_exit(smx_process_t process, int_f_pvoid_t fun, void *data)
711 {
712   smx_simcall_t simcall = SIMIX_simcall_mine();
713
714   simcall->call = SIMCALL_PROCESS_ON_EXIT;
715   simcall->process_on_exit.process = process;
716   simcall->process_on_exit.fun = fun;
717   simcall->process_on_exit.data = data;
718
719   SIMIX_simcall_push(simcall->issuer);
720 }
721 /**
722  * \ingroup simix_process_management
723  * \brief Sets the process to be auto-restarted or not by SIMIX when its host comes back up.
724  * Will restart the process when the host comes back up if auto_restart is set to 1.
725  */
726
727 XBT_PUBLIC(void) simcall_process_auto_restart_set(smx_process_t process, int auto_restart)
728 {
729   smx_simcall_t simcall = SIMIX_simcall_mine();
730
731   simcall->call = SIMCALL_PROCESS_AUTO_RESTART_SET;
732   simcall->process_auto_restart.process = process;
733   simcall->process_auto_restart.auto_restart = auto_restart;
734
735   SIMIX_simcall_push(simcall->issuer);
736 }
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_active()) /* 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_active()) /* 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_active()) /* 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_active()) /* 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_active()) /* 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_active()) /* 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_active()) {
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_active()) /* 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_active()) {
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_active()) /* 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
1025
1026 /**
1027  * \ingroup simix_comm_management
1028  */
1029 smx_action_t simcall_comm_iprobe(smx_rdv_t rdv, int src, int tag,
1030                                 int (*match_fun)(void *, void *, smx_action_t), void *data)
1031 {
1032   xbt_assert(rdv, "No rendez-vous point defined for iprobe");
1033
1034   smx_simcall_t simcall = SIMIX_simcall_mine();
1035
1036   simcall->call = SIMCALL_COMM_IPROBE;
1037   simcall->comm_iprobe.rdv = rdv;
1038   simcall->comm_iprobe.src = src;
1039   simcall->comm_iprobe.match_fun = match_fun;
1040   simcall->comm_iprobe.data = data;
1041   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1042     simcall->comm_iprobe.result = NULL;
1043   SIMIX_simcall_push(simcall->issuer);
1044   return simcall->comm_iprobe.result;
1045 }
1046
1047
1048 void simcall_comm_destroy(smx_action_t comm)
1049 {
1050   xbt_assert(comm, "Invalid parameter");
1051
1052   /* FIXME remove this simcall type: comms are auto-destroyed now */
1053
1054   /*
1055   smx_simcall_t simcall = simcall_mine();
1056
1057   simcall->call = SIMCALL_COMM_DESTROY;
1058   simcall->comm_destroy.comm = comm;
1059
1060   SIMIX_simcall_push(simcall->issuer);
1061   */
1062 }
1063 /**
1064  * \ingroup simix_comm_management
1065  */
1066 void simcall_comm_cancel(smx_action_t comm)
1067 {
1068   smx_simcall_t simcall = SIMIX_simcall_mine();
1069
1070   simcall->call = SIMCALL_COMM_CANCEL;
1071   simcall->comm_cancel.comm = comm;
1072
1073   SIMIX_simcall_push(simcall->issuer);
1074 }
1075 /**
1076  * \ingroup simix_comm_management
1077  */
1078 unsigned int simcall_comm_waitany(xbt_dynar_t comms)
1079 {
1080   smx_simcall_t simcall = SIMIX_simcall_mine();
1081
1082   simcall->call = SIMCALL_COMM_WAITANY;
1083   simcall->comm_waitany.comms = comms;
1084   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1085     simcall->comm_waitany.result = -1;
1086
1087   SIMIX_simcall_push(simcall->issuer);
1088   return simcall->comm_waitany.result;
1089 }
1090 /**
1091  * \ingroup simix_comm_management
1092  */
1093 int simcall_comm_testany(xbt_dynar_t comms)
1094 {
1095   smx_simcall_t simcall = SIMIX_simcall_mine();
1096   if (xbt_dynar_is_empty(comms))
1097     return -1;
1098
1099   simcall->call = SIMCALL_COMM_TESTANY;
1100   simcall->comm_testany.comms = comms;
1101     if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1102       simcall->comm_testany.result = -1;
1103
1104   SIMIX_simcall_push(simcall->issuer);
1105   return simcall->comm_testany.result;
1106 }
1107 /**
1108  * \ingroup simix_comm_management
1109  */
1110 void simcall_comm_wait(smx_action_t comm, double timeout)
1111 {
1112   xbt_assert(isfinite(timeout), "timeout is not finite!");
1113   
1114   smx_simcall_t simcall = SIMIX_simcall_mine();
1115
1116   simcall->call = SIMCALL_COMM_WAIT;
1117   simcall->comm_wait.comm = comm;
1118   simcall->comm_wait.timeout = timeout;
1119
1120   SIMIX_simcall_push(simcall->issuer);
1121 }
1122
1123 #ifdef HAVE_TRACING
1124 /**
1125  * \brief Set the category of an action.
1126  *
1127  * This functions changes the category only. It calls a surf function.
1128  * \param execution The execution action
1129  * \param category The tracing category
1130  */
1131 void simcall_set_category(smx_action_t action, const char *category)
1132 {
1133   if (category == NULL) {
1134     return;
1135   }
1136
1137   smx_simcall_t simcall = SIMIX_simcall_mine();
1138
1139   simcall->call = SIMCALL_SET_CATEGORY;
1140   simcall->set_category.action = action;
1141   simcall->set_category.category = category;
1142
1143   SIMIX_simcall_push(simcall->issuer);
1144 }
1145 #endif
1146 /**
1147  * \ingroup simix_comm_management
1148  *
1149  */
1150 int simcall_comm_test(smx_action_t comm)
1151 {
1152   smx_simcall_t simcall = SIMIX_simcall_mine();
1153
1154   simcall->call = SIMCALL_COMM_TEST;
1155   simcall->comm_test.comm = comm;
1156   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1157     simcall->comm_test.result = -1;
1158
1159   SIMIX_simcall_push(simcall->issuer);
1160   return simcall->comm_test.result;
1161 }
1162 /**
1163  * \ingroup simix_comm_management
1164  *
1165  */
1166 double simcall_comm_get_remains(smx_action_t comm)
1167 {
1168   smx_simcall_t simcall = SIMIX_simcall_mine();
1169
1170   simcall->call = SIMCALL_COMM_GET_REMAINS;
1171   simcall->comm_get_remains.comm = comm;
1172   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1173     simcall->comm_get_remains.result = 0.0;
1174
1175   SIMIX_simcall_push(simcall->issuer);
1176   return simcall->comm_get_remains.result;
1177 }
1178 /**
1179  * \ingroup simix_comm_management
1180  *
1181  */
1182 e_smx_state_t simcall_comm_get_state(smx_action_t comm)
1183 {
1184   smx_simcall_t simcall = SIMIX_simcall_mine();
1185
1186   simcall->call = SIMCALL_COMM_GET_STATE;
1187   simcall->comm_get_state.comm = comm;
1188   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1189     simcall->comm_get_state.result = -1;
1190
1191   SIMIX_simcall_push(simcall->issuer);
1192   return simcall->comm_get_state.result;
1193 }
1194 /**
1195  * \ingroup simix_comm_management
1196  *
1197  */
1198 void *simcall_comm_get_src_data(smx_action_t comm)
1199 {
1200   smx_simcall_t simcall = SIMIX_simcall_mine();
1201
1202   simcall->call = SIMCALL_COMM_GET_SRC_DATA;
1203   simcall->comm_get_src_data.comm = comm;
1204   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1205     simcall->comm_get_src_data.result = NULL;
1206
1207   SIMIX_simcall_push(simcall->issuer);
1208   return simcall->comm_get_src_data.result;
1209 }
1210 /**
1211  * \ingroup simix_comm_management
1212  *
1213  */
1214 void *simcall_comm_get_dst_data(smx_action_t comm)
1215 {
1216   smx_simcall_t simcall = SIMIX_simcall_mine();
1217
1218   simcall->call = SIMCALL_COMM_GET_DST_DATA;
1219   simcall->comm_get_dst_data.comm = comm;
1220   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1221     simcall->comm_get_dst_data.result = NULL;
1222
1223   SIMIX_simcall_push(simcall->issuer);
1224   return simcall->comm_get_dst_data.result;
1225 }
1226 /**
1227  * \ingroup simix_comm_management
1228  *
1229  */
1230 smx_process_t simcall_comm_get_src_proc(smx_action_t comm)
1231 {
1232   smx_simcall_t simcall = SIMIX_simcall_mine();
1233
1234   simcall->call = SIMCALL_COMM_GET_SRC_PROC;
1235   simcall->comm_get_src_proc.comm = comm;
1236   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1237     simcall->comm_get_src_proc.result = NULL;
1238
1239   SIMIX_simcall_push(simcall->issuer);
1240   return simcall->comm_get_src_proc.result;
1241 }
1242 /**
1243  * \ingroup simix_comm_management
1244  *
1245  */
1246 smx_process_t simcall_comm_get_dst_proc(smx_action_t comm)
1247 {
1248   smx_simcall_t simcall = SIMIX_simcall_mine();
1249
1250   simcall->call = SIMCALL_COMM_GET_DST_PROC;
1251   simcall->comm_get_dst_proc.comm = comm;
1252   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1253     simcall->comm_get_dst_proc.result = NULL;
1254
1255   SIMIX_simcall_push(simcall->issuer);
1256   return simcall->comm_get_dst_proc.result;
1257 }
1258
1259 #ifdef HAVE_LATENCY_BOUND_TRACKING
1260 int simcall_comm_is_latency_bounded(smx_action_t comm)
1261 {
1262   smx_simcall_t simcall = SIMIX_simcall_mine();
1263
1264   simcall->call = SIMCALL_COMM_IS_LATENCY_BOUNDED;
1265   simcall->comm_is_latency_bounded.comm = comm;
1266   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1267     simcall->comm_is_latency_bounded.result = -1;
1268
1269   SIMIX_simcall_push(simcall->issuer);
1270   return simcall->comm_is_latency_bounded.result;
1271 }
1272 #endif
1273 /**
1274  * \ingroup simix_synchro_management
1275  *
1276  */
1277 smx_mutex_t simcall_mutex_init(void)
1278 {
1279   if(!simix_global) {
1280     fprintf(stderr,"You must run MSG_init before using MSG\n"); // We can't use xbt_die since we may get there before the initialization
1281     xbt_abort();
1282   }
1283   smx_simcall_t simcall = SIMIX_simcall_mine();
1284
1285   simcall->call = SIMCALL_MUTEX_INIT;
1286   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1287     simcall->mutex_init.result = NULL;
1288
1289   SIMIX_simcall_push(simcall->issuer);
1290   return simcall->mutex_init.result;
1291 }
1292 /**
1293  * \ingroup simix_synchro_management
1294  *
1295  */
1296 void simcall_mutex_destroy(smx_mutex_t mutex)
1297 {
1298   smx_simcall_t simcall = SIMIX_simcall_mine();
1299
1300   simcall->call = SIMCALL_MUTEX_DESTROY;
1301   simcall->mutex_destroy.mutex = mutex;
1302
1303   SIMIX_simcall_push(simcall->issuer);
1304 }
1305 /**
1306  * \ingroup simix_synchro_management
1307  *
1308  */
1309 void simcall_mutex_lock(smx_mutex_t mutex)
1310 {
1311   smx_simcall_t simcall = SIMIX_simcall_mine();
1312
1313   simcall->call = SIMCALL_MUTEX_LOCK;
1314   simcall->mutex_lock.mutex = mutex;
1315
1316   SIMIX_simcall_push(simcall->issuer);
1317 }
1318 /**
1319  * \ingroup simix_synchro_management
1320  *
1321  */
1322 int simcall_mutex_trylock(smx_mutex_t mutex)
1323 {
1324   smx_simcall_t simcall = SIMIX_simcall_mine();
1325
1326   simcall->call = SIMCALL_MUTEX_TRYLOCK;
1327   simcall->mutex_trylock.mutex = mutex;
1328   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1329     simcall->mutex_trylock.result = -1;
1330
1331   SIMIX_simcall_push(simcall->issuer);
1332   return simcall->mutex_trylock.result;
1333 }
1334 /**
1335  * \ingroup simix_synchro_management
1336  *
1337  */
1338 void simcall_mutex_unlock(smx_mutex_t mutex)
1339 {
1340   smx_simcall_t simcall = SIMIX_simcall_mine();
1341
1342   simcall->call = SIMCALL_MUTEX_UNLOCK;
1343   simcall->mutex_unlock.mutex = mutex;
1344
1345   SIMIX_simcall_push(simcall->issuer);
1346 }
1347 /**
1348  * \ingroup simix_synchro_management
1349  *
1350  */
1351 smx_cond_t simcall_cond_init(void)
1352 {
1353   smx_simcall_t simcall = SIMIX_simcall_mine();
1354
1355   simcall->call = SIMCALL_COND_INIT;
1356   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1357     simcall->cond_init.result = NULL;
1358
1359   SIMIX_simcall_push(simcall->issuer);
1360   return simcall->cond_init.result;
1361 }
1362 /**
1363  * \ingroup simix_synchro_management
1364  *
1365  */
1366 void simcall_cond_destroy(smx_cond_t cond)
1367 {
1368   smx_simcall_t simcall = SIMIX_simcall_mine();
1369
1370   simcall->call = SIMCALL_COND_DESTROY;
1371   simcall->cond_destroy.cond = cond;
1372
1373   SIMIX_simcall_push(simcall->issuer);
1374 }
1375 /**
1376  * \ingroup simix_synchro_management
1377  *
1378  */
1379 void simcall_cond_signal(smx_cond_t cond)
1380 {
1381   smx_simcall_t simcall = SIMIX_simcall_mine();
1382
1383   simcall->call = SIMCALL_COND_SIGNAL;
1384   simcall->cond_signal.cond = cond;
1385
1386   SIMIX_simcall_push(simcall->issuer);
1387 }
1388 /**
1389  * \ingroup simix_synchro_management
1390  *
1391  */
1392 void simcall_cond_wait(smx_cond_t cond, smx_mutex_t mutex)
1393 {
1394   smx_simcall_t simcall = SIMIX_simcall_mine();
1395
1396   simcall->call = SIMCALL_COND_WAIT;
1397   simcall->cond_wait.cond = cond;
1398   simcall->cond_wait.mutex = mutex;
1399
1400   SIMIX_simcall_push(simcall->issuer);
1401 }
1402 /**
1403  * \ingroup simix_synchro_management
1404  *
1405  */
1406 void simcall_cond_wait_timeout(smx_cond_t cond,
1407                                  smx_mutex_t mutex,
1408                                  double timeout)
1409 {
1410   xbt_assert(isfinite(timeout), "timeout is not finite!");
1411   
1412   smx_simcall_t simcall = SIMIX_simcall_mine();
1413
1414   simcall->call = SIMCALL_COND_WAIT_TIMEOUT;
1415   simcall->cond_wait_timeout.cond = cond;
1416   simcall->cond_wait_timeout.mutex = mutex;
1417   simcall->cond_wait_timeout.timeout = timeout;
1418
1419   SIMIX_simcall_push(simcall->issuer);
1420 }
1421 /**
1422  * \ingroup simix_synchro_management
1423  *
1424  */
1425 void simcall_cond_broadcast(smx_cond_t cond)
1426 {
1427   smx_simcall_t simcall = SIMIX_simcall_mine();
1428
1429   simcall->call = SIMCALL_COND_BROADCAST;
1430   simcall->cond_broadcast.cond = cond;
1431
1432   SIMIX_simcall_push(simcall->issuer);
1433 }
1434 /**
1435  * \ingroup simix_synchro_management
1436  *
1437  */
1438 smx_sem_t simcall_sem_init(int capacity)
1439 {
1440   smx_simcall_t simcall = SIMIX_simcall_mine();
1441
1442   simcall->call = SIMCALL_SEM_INIT;
1443   simcall->sem_init.capacity = capacity;
1444   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1445     simcall->sem_init.result = NULL;
1446
1447   SIMIX_simcall_push(simcall->issuer);
1448   return simcall->sem_init.result;
1449 }
1450 /**
1451  * \ingroup simix_synchro_management
1452  *
1453  */
1454 void simcall_sem_destroy(smx_sem_t sem)
1455 {
1456   smx_simcall_t simcall = SIMIX_simcall_mine();
1457
1458   simcall->call = SIMCALL_SEM_DESTROY;
1459   simcall->sem_destroy.sem = sem;
1460
1461   SIMIX_simcall_push(simcall->issuer);
1462 }
1463 /**
1464  * \ingroup simix_synchro_management
1465  *
1466  */
1467 void simcall_sem_release(smx_sem_t sem)
1468 {
1469   smx_simcall_t simcall = SIMIX_simcall_mine();
1470
1471   simcall->call = SIMCALL_SEM_RELEASE;
1472   simcall->sem_release.sem = sem;
1473
1474   SIMIX_simcall_push(simcall->issuer);
1475 }
1476 /**
1477  * \ingroup simix_synchro_management
1478  *
1479  */
1480 int simcall_sem_would_block(smx_sem_t sem)
1481 {
1482   smx_simcall_t simcall = SIMIX_simcall_mine();
1483
1484   simcall->call = SIMCALL_SEM_WOULD_BLOCK;
1485   simcall->sem_would_block.sem = sem;
1486   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1487     simcall->sem_would_block.result = -1;
1488
1489   SIMIX_simcall_push(simcall->issuer);
1490   return simcall->sem_would_block.result;
1491 }
1492 /**
1493  * \ingroup simix_synchro_management
1494  *
1495  */
1496 void simcall_sem_acquire(smx_sem_t sem)
1497 {
1498   smx_simcall_t simcall = SIMIX_simcall_mine();
1499
1500   simcall->call = SIMCALL_SEM_ACQUIRE;
1501   simcall->sem_acquire.sem = sem;
1502
1503   SIMIX_simcall_push(simcall->issuer);
1504 }
1505 /**
1506  * \ingroup simix_synchro_management
1507  *
1508  */
1509 void simcall_sem_acquire_timeout(smx_sem_t sem, double timeout)
1510 {
1511   xbt_assert(isfinite(timeout), "timeout is not finite!");
1512   
1513   smx_simcall_t simcall = SIMIX_simcall_mine();
1514
1515   simcall->call = SIMCALL_SEM_ACQUIRE_TIMEOUT;
1516   simcall->sem_acquire_timeout.sem = sem;
1517   simcall->sem_acquire_timeout.timeout = timeout;
1518
1519   SIMIX_simcall_push(simcall->issuer);
1520 }
1521 /**
1522  * \ingroup simix_synchro_management
1523  *
1524  */
1525 int simcall_sem_get_capacity(smx_sem_t sem)
1526 {
1527   smx_simcall_t simcall = SIMIX_simcall_mine();
1528
1529   simcall->call = SIMCALL_SEM_GET_CAPACITY;
1530   simcall->sem_get_capacity.sem = sem;
1531   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1532     simcall->sem_get_capacity.result = -1;
1533
1534   SIMIX_simcall_push(simcall->issuer);
1535   return simcall->sem_get_capacity.result;
1536 }
1537 /**
1538  * \ingroup simix_file_management
1539  *
1540  */
1541 double simcall_file_read(void* ptr, size_t size, size_t nmemb, smx_file_t stream)
1542 {
1543   smx_simcall_t simcall = SIMIX_simcall_mine();
1544
1545   simcall->call = SIMCALL_FILE_READ;
1546   simcall->file_read.ptr = ptr;
1547   simcall->file_read.size = size;
1548   simcall->file_read.nmemb = nmemb;
1549   simcall->file_read.stream = stream;
1550   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1551     simcall->file_read.result = 0.0;
1552   SIMIX_simcall_push(simcall->issuer);
1553
1554   return simcall->file_read.result;
1555 }
1556 /**
1557  * \ingroup simix_file_management
1558  *
1559  */
1560 size_t simcall_file_write(const void* ptr, size_t size, size_t nmemb, smx_file_t stream)
1561 {
1562   smx_simcall_t simcall = SIMIX_simcall_mine();
1563
1564   simcall->call = SIMCALL_FILE_WRITE;
1565   simcall->file_write.ptr = ptr;
1566   simcall->file_write.size = size;
1567   simcall->file_write.nmemb = nmemb;
1568   simcall->file_write.stream = stream;
1569   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1570     simcall->file_write.result = 0;
1571   SIMIX_simcall_push(simcall->issuer);
1572
1573   return simcall->file_write.result;
1574 }
1575 /**
1576  * \ingroup simix_file_management
1577  * \brief
1578  */
1579 smx_file_t simcall_file_open(const char* mount, const char* path, const char* mode)
1580 {
1581   smx_simcall_t simcall = SIMIX_simcall_mine();
1582
1583   simcall->call = SIMCALL_FILE_OPEN;
1584   simcall->file_open.mount = mount;
1585   simcall->file_open.path = path;
1586   simcall->file_open.mode = mode;
1587   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1588     simcall->file_open.result = NULL;
1589   SIMIX_simcall_push(simcall->issuer);
1590
1591   return simcall->file_open.result;
1592 }
1593 /**
1594  * \ingroup simix_file_management
1595  *
1596  */
1597 int simcall_file_close(smx_file_t fp)
1598 {
1599   smx_simcall_t simcall = SIMIX_simcall_mine();
1600
1601   simcall->call = SIMCALL_FILE_CLOSE;
1602   simcall->file_close.fp = fp;
1603   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1604     simcall->file_close.result = -1;
1605   SIMIX_simcall_push(simcall->issuer);
1606
1607   return simcall->file_close.result;
1608 }
1609 /**
1610  * \ingroup simix_file_management
1611  *
1612  */
1613 int simcall_file_stat(smx_file_t fd, s_file_stat_t *buf)
1614 {
1615   smx_simcall_t simcall = SIMIX_simcall_mine();
1616   simcall->call = SIMCALL_FILE_STAT;
1617   simcall->file_stat.fd = fd;
1618   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1619     simcall->file_stat.result = -1;
1620
1621   SIMIX_simcall_push(simcall->issuer);
1622
1623   *buf = simcall->file_stat.buf;
1624
1625   return simcall->file_stat.result;
1626 }
1627
1628 /**
1629  * \ingroup simix_file_management
1630  *
1631  */
1632 int simcall_file_unlink(smx_file_t fd)
1633 {
1634   smx_simcall_t simcall = SIMIX_simcall_mine();
1635   simcall->call = SIMCALL_FILE_UNLINK;
1636   simcall->file_unlink.fd = fd;
1637   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1638     simcall->file_unlink.result = -1;
1639
1640   SIMIX_simcall_push(simcall->issuer);
1641
1642   return simcall->file_unlink.result;
1643 }
1644
1645 /**
1646  * \ingroup simix_file_management
1647  *
1648  */
1649 xbt_dict_t simcall_file_ls(const char* mount, const char* path)
1650 {
1651   smx_simcall_t simcall = SIMIX_simcall_mine();
1652   simcall->call = SIMCALL_FILE_LS;
1653   simcall->file_ls.mount = mount;
1654   simcall->file_ls.path = path;
1655   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1656     simcall->file_ls.result = NULL;
1657
1658   SIMIX_simcall_push(simcall->issuer);
1659
1660   return simcall->file_ls.result;
1661 }
1662
1663 #ifdef HAVE_MC
1664
1665 void *simcall_mc_snapshot(void)
1666 {
1667   smx_simcall_t simcall = SIMIX_simcall_mine();
1668   simcall->call = SIMCALL_MC_SNAPSHOT;
1669   
1670   SIMIX_simcall_push(simcall->issuer);
1671
1672   return simcall->mc_snapshot.s;
1673 }
1674
1675 int simcall_mc_compare_snapshots(void *s1, void *s2){
1676   
1677   smx_simcall_t simcall = SIMIX_simcall_mine();
1678   simcall->call = SIMCALL_MC_COMPARE_SNAPSHOTS;
1679   simcall->mc_compare_snapshots.snapshot1 = s1;
1680   simcall->mc_compare_snapshots.snapshot2 = s2;
1681   
1682   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1683     simcall->mc_compare_snapshots.result = -1;
1684   
1685   SIMIX_simcall_push(simcall->issuer);
1686   
1687   return simcall->mc_compare_snapshots.result;
1688 }
1689
1690 #endif /* HAVE_MC */
1691
1692 /* ****************************************************************************************** */
1693 /* TUTORIAL: New API                                                                          */
1694 /* All functions for simcall                                                                  */
1695 /* ****************************************************************************************** */
1696 int simcall_new_api_fct(const char* param1, double param2){
1697   smx_simcall_t simcall = SIMIX_simcall_mine();
1698   simcall->call = SIMCALL_NEW_API_INIT;
1699   simcall->new_api.param1 = param1;
1700   simcall->new_api.param2 = param2;
1701
1702   SIMIX_simcall_push(simcall->issuer);
1703   return simcall->new_api.result;
1704 }
1705
1706 /* ************************************************************************** */
1707
1708 /** @brief returns a printable string representing a simcall */
1709 const char *SIMIX_simcall_name(e_smx_simcall_t kind) {
1710   return simcall_names[kind];
1711 }