Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Move SIMCALL_HOST_EXECUTE to the new simcall architecture for initial testing.
[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   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
387     simcall->host_execution_wait.result = -1;
388   SIMIX_simcall_push(simcall->issuer);
389   return simcall->host_execution_wait.result;
390 }
391
392 /**
393  * \ingroup simix_process_management
394  * \brief Creates and runs a new SIMIX process.
395  *
396  * The structure and the corresponding thread are created and put in the list of ready processes.
397  *
398  * \param process the process created will be stored in this pointer
399  * \param name a name for the process. It is for user-level information and can be NULL.
400  * \param code the main function of the process
401  * \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.
402  * It can be retrieved with the function \ref simcall_process_get_data.
403  * \param hostname name of the host where the new agent is executed.
404  * \param kill_time time when the process is killed
405  * \param argc first argument passed to \a code
406  * \param argv second argument passed to \a code
407  * \param properties the properties of the process
408  * \param auto_restart either it is autorestarting or not.
409  */
410 void simcall_process_create(smx_process_t *process, const char *name,
411                               xbt_main_func_t code,
412                               void *data,
413                               const char *hostname,
414                               double kill_time,
415                               int argc, char **argv,
416                               xbt_dict_t properties,
417                               int auto_restart)
418 {
419   smx_simcall_t simcall = SIMIX_simcall_mine();
420
421   simcall->call = SIMCALL_PROCESS_CREATE;
422   simcall->process_create.process = process;
423   simcall->process_create.name = name;
424   simcall->process_create.code = code;
425   simcall->process_create.data = data;
426   simcall->process_create.hostname = hostname;
427   simcall->process_create.kill_time = kill_time;
428   simcall->process_create.argc = argc;
429   simcall->process_create.argv = argv;
430   simcall->process_create.properties = properties;
431   simcall->process_create.auto_restart = auto_restart;
432   SIMIX_simcall_push(simcall->issuer);
433 }
434
435 /**
436  * \ingroup simix_process_management
437  * \brief Kills a SIMIX process.
438  *
439  * This function simply kills a  process.
440  *
441  * \param process poor victim
442  */
443 void simcall_process_kill(smx_process_t process)
444 {
445   smx_simcall_t simcall = SIMIX_simcall_mine();
446
447   simcall->call = SIMCALL_PROCESS_KILL;
448   simcall->process_kill.process = process;
449   SIMIX_simcall_push(simcall->issuer);
450 }
451
452 /**
453  * \ingroup simix_process_management
454  * \brief Kills all SIMIX processes.
455  */
456 void simcall_process_killall(void)
457 {
458   smx_simcall_t simcall = SIMIX_simcall_mine();
459
460   simcall->call = SIMCALL_PROCESS_KILLALL;
461   SIMIX_simcall_push(simcall->issuer);
462 }
463
464 /**
465  * \ingroup simix_process_management
466  * \brief Cleans up a SIMIX process.
467  * \param process poor victim (must have already been killed)
468  */
469 void simcall_process_cleanup(smx_process_t process)
470 {
471   smx_simcall_t simcall = SIMIX_simcall_mine();
472
473   simcall->call = SIMCALL_PROCESS_CLEANUP;
474   simcall->process_cleanup.process = process;
475   SIMIX_simcall_push(simcall->issuer);
476 }
477
478 /**
479  * \ingroup simix_process_management
480  * \brief Migrates an agent to another location.
481  *
482  * This function changes the value of the host on which \a process is running.
483  *
484  * \param process the process to migrate
485  * \param dest name of the new host
486  */
487 void simcall_process_change_host(smx_process_t process, smx_host_t dest)
488 {
489   smx_simcall_t simcall = SIMIX_simcall_mine();
490
491   simcall->call = SIMCALL_PROCESS_CHANGE_HOST;
492   simcall->process_change_host.process = process;
493   simcall->process_change_host.dest = dest;
494   SIMIX_simcall_push(simcall->issuer);
495 }
496
497 /**
498  * \ingroup simix_process_management
499  * \brief Suspends a process.
500  *
501  * This function suspends the process by suspending the action
502  * it was waiting for completion.
503  *
504  * \param process a SIMIX process
505  */
506 void simcall_process_suspend(smx_process_t process)
507 {
508   xbt_assert(process, "Invalid parameters");
509
510   smx_simcall_t simcall = SIMIX_simcall_mine();
511
512   simcall->call = SIMCALL_PROCESS_SUSPEND;
513   simcall->process_suspend.process = process;
514   SIMIX_simcall_push(simcall->issuer);
515 }
516
517 /**
518  * \ingroup simix_process_management
519  * \brief Resumes a suspended process.
520  *
521  * This function resumes a suspended process by resuming the action
522  * it was waiting for completion.
523  *
524  * \param process a SIMIX process
525  */
526 void simcall_process_resume(smx_process_t process)
527 {
528   smx_simcall_t simcall = SIMIX_simcall_mine();
529
530   simcall->call = SIMCALL_PROCESS_RESUME;
531   simcall->process_resume.process = process;
532   SIMIX_simcall_push(simcall->issuer);
533 }
534
535 /**
536  * \ingroup simix_process_management
537  * \brief Returns the amount of SIMIX processes in the system
538  *
539  * Maestro internal process is not counted, only user code processes are
540  */
541 int simcall_process_count(void)
542 {
543   smx_simcall_t simcall = SIMIX_simcall_mine();
544
545   simcall->call = SIMCALL_PROCESS_COUNT;
546   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
547     simcall->process_count.result = -1;
548   SIMIX_simcall_push(simcall->issuer);
549   return simcall->process_count.result;
550 }
551
552 /**
553  * \ingroup simix_process_management
554  * \brief Return the user data of a #smx_process_t.
555  * \param process a SIMIX process
556  * \return the user data of this process
557  */
558 void* simcall_process_get_data(smx_process_t process)
559 {
560   if (process == SIMIX_process_self()) {
561     /* avoid a simcall if this function is called by the process itself */
562     return SIMIX_process_get_data(process);
563   }
564
565   smx_simcall_t simcall = SIMIX_simcall_mine();
566
567   simcall->call = SIMCALL_PROCESS_GET_DATA;
568   simcall->process_get_data.process = process;
569   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
570     simcall->process_get_data.result = NULL;
571   SIMIX_simcall_push(simcall->issuer);
572   return simcall->process_get_data.result;
573 }
574
575 /**
576  * \ingroup simix_process_management
577  * \brief Set the user data of a #smx_process_t.
578  *
579  * This functions sets the user data associated to \a process.
580  * \param process SIMIX process
581  * \param data User data
582  */
583 void simcall_process_set_data(smx_process_t process, void *data)
584 {
585   if (process == SIMIX_process_self()) {
586     /* avoid a simcall if this function is called by the process itself */
587     SIMIX_process_self_set_data(process, data);
588   }
589   else {
590
591     smx_simcall_t simcall = SIMIX_simcall_mine();
592
593     simcall->call = SIMCALL_PROCESS_SET_DATA;
594     simcall->process_set_data.process = process;
595     simcall->process_set_data.data = data;
596     SIMIX_simcall_push(simcall->issuer);
597   }
598 }
599
600 /**
601  * \ingroup simix_process_management
602  * \brief Set the kill time of a process.
603  * \param process a process
604  * \param kill_time a double
605  */
606 void simcall_process_set_kill_time(smx_process_t process, double kill_time)
607 {
608
609   if (kill_time > SIMIX_get_clock()) {
610     if (simix_global->kill_process_function) {
611       XBT_DEBUG("Set kill time %f for process %s(%s)",kill_time, process->name,
612           process->smx_host->name);
613       SIMIX_timer_set(kill_time, simix_global->kill_process_function, process);
614     }
615   }
616 }
617
618 /**
619  * \ingroup simix_process_management
620  * \brief Return the location on which an agent is running.
621  *
622  * This functions returns the smx_host_t corresponding to the location on which
623  * \a process is running.
624  * \param process SIMIX process
625  * \return SIMIX host
626  */
627 smx_host_t simcall_process_get_host(smx_process_t process)
628 {
629   smx_simcall_t simcall = SIMIX_simcall_mine();
630
631   simcall->call = SIMCALL_PROCESS_GET_HOST;
632   simcall->process_get_host.process = process;
633   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
634     simcall->process_get_host.result = NULL;
635   SIMIX_simcall_push(simcall->issuer);
636   return simcall->process_get_host.result;
637 }
638
639 /**
640  * \ingroup simix_process_management
641  * \brief Return the name of an agent.
642  *
643  * This functions checks whether \a process is a valid pointer or not and return its name.
644  * \param process SIMIX process
645  * \return The process name
646  */
647 const char* simcall_process_get_name(smx_process_t process)
648 {
649   if (process == SIMIX_process_self()) {
650     /* avoid a simcall if this function is called by the process itself */
651     return process->name;
652   }
653
654   smx_simcall_t simcall = SIMIX_simcall_mine();
655
656   simcall->call = SIMCALL_PROCESS_GET_NAME;
657   simcall->process_get_name.process = process;
658   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
659     simcall->process_get_name.result = NULL;
660   SIMIX_simcall_push(simcall->issuer);
661   return simcall->process_get_name.result;
662 }
663
664 /**
665  * \ingroup simix_process_management
666  * \brief Returns true if the process is suspended .
667  *
668  * This checks whether a process is suspended or not by inspecting the task on which it was waiting for the completion.
669  * \param process SIMIX process
670  * \return 1, if the process is suspended, else 0.
671  */
672 int simcall_process_is_suspended(smx_process_t process)
673 {
674   smx_simcall_t simcall = SIMIX_simcall_mine();
675
676   simcall->call = SIMCALL_PROCESS_IS_SUSPENDED;
677   simcall->process_is_suspended.process = process;
678   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
679     simcall->process_is_suspended.result = -1;
680   SIMIX_simcall_push(simcall->issuer);
681   return simcall->process_is_suspended.result;
682 }
683
684 /**
685  * \ingroup simix_process_management
686  * \brief Return the properties
687  *
688  * This functions returns the properties associated with this process
689  */
690 xbt_dict_t simcall_process_get_properties(smx_process_t process)
691 {
692   smx_simcall_t simcall = SIMIX_simcall_mine();
693
694   simcall->call = SIMCALL_PROCESS_GET_PROPERTIES;
695   simcall->process_get_properties.process = process;
696   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
697     simcall->process_get_properties.result = NULL;
698   SIMIX_simcall_push(simcall->issuer);
699   return simcall->process_get_properties.result;
700 }
701 /**
702  * \ingroup simix_process_management
703  * \brief Add an on_exit function
704  * Add an on_exit function which will be executed when the process exits/is killed.
705  */
706 XBT_PUBLIC(void) simcall_process_on_exit(smx_process_t process, int_f_pvoid_t fun, void *data)
707 {
708   smx_simcall_t simcall = SIMIX_simcall_mine();
709
710   simcall->call = SIMCALL_PROCESS_ON_EXIT;
711   simcall->process_on_exit.process = process;
712   simcall->process_on_exit.fun = fun;
713   simcall->process_on_exit.data = data;
714
715   SIMIX_simcall_push(simcall->issuer);
716 }
717 /**
718  * \ingroup simix_process_management
719  * \brief Sets the process to be auto-restarted or not by SIMIX when its host comes back up.
720  * Will restart the process when the host comes back up if auto_restart is set to 1.
721  */
722
723 XBT_PUBLIC(void) simcall_process_auto_restart_set(smx_process_t process, int auto_restart)
724 {
725   smx_simcall_t simcall = SIMIX_simcall_mine();
726
727   simcall->call = SIMCALL_PROCESS_AUTO_RESTART_SET;
728   simcall->process_auto_restart.process = process;
729   simcall->process_auto_restart.auto_restart = auto_restart;
730
731   SIMIX_simcall_push(simcall->issuer);
732 }
733
734 /**
735  * \ingroup simix_process_management
736  * \brief Restarts the process, killing it and starting it again from scratch.
737  */
738 XBT_PUBLIC(smx_process_t) simcall_process_restart(smx_process_t process)
739 {
740   smx_simcall_t simcall = SIMIX_simcall_mine();
741
742   simcall->call = SIMCALL_PROCESS_RESTART;
743   simcall->process_restart.process = process;
744   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
745     simcall->process_restart.result = NULL;
746
747   SIMIX_simcall_push(simcall->issuer);
748
749   return simcall->process_restart.result;
750 }
751 /**
752  * \ingroup simix_process_management
753  * \brief Creates a new sleep SIMIX action.
754  *
755  * This function creates a SURF action and allocates the data necessary
756  * to create the SIMIX action. It can raise a host_error exception if the
757  * host crashed. The default SIMIX name of the action is "sleep".
758  *
759  *   \param duration Time duration of the sleep.
760  *   \return A result telling whether the sleep was successful
761  */
762 e_smx_state_t simcall_process_sleep(double duration)
763 {
764   /* checking for infinite values */
765   xbt_assert(isfinite(duration), "duration is not finite!");
766   
767   smx_simcall_t simcall = SIMIX_simcall_mine();
768
769   simcall->call = SIMCALL_PROCESS_SLEEP;
770   simcall->process_sleep.duration = duration;
771   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
772     simcall->process_sleep.result = -1;
773   SIMIX_simcall_push(simcall->issuer);
774   return simcall->process_sleep.result;
775 }
776
777 /**
778  *  \ingroup simix_rdv_management
779  *  \brief Creates a new rendez-vous point
780  *  \param name The name of the rendez-vous point
781  *  \return The created rendez-vous point
782  */
783 smx_rdv_t simcall_rdv_create(const char *name)
784 {
785   smx_simcall_t simcall = SIMIX_simcall_mine();
786
787   simcall->call = SIMCALL_RDV_CREATE;
788   simcall->rdv_create.name = name;
789   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
790     simcall->rdv_create.result = NULL;
791
792   SIMIX_simcall_push(simcall->issuer);
793   return simcall->rdv_create.result;
794 }
795
796
797 /**
798  *  \ingroup simix_rdv_management
799  *  \brief Destroy a rendez-vous point
800  *  \param rdv The rendez-vous point to destroy
801  */
802 void simcall_rdv_destroy(smx_rdv_t rdv)
803 {
804   smx_simcall_t simcall = SIMIX_simcall_mine();
805
806   simcall->call = SIMCALL_RDV_DESTROY;
807   simcall->rdv_destroy.rdv = rdv;
808
809   SIMIX_simcall_push(simcall->issuer);
810 }
811 /**
812  *  \ingroup simix_rdv_management
813  *  \brief Returns a rendez-vous point knowing its name
814  */
815 smx_rdv_t simcall_rdv_get_by_name(const char *name)
816 {
817   xbt_assert(name != NULL, "Invalid parameter for simcall_rdv_get_by_name (name is NULL)");
818
819   /* FIXME: this is a horrible lost of performance, so we hack it out by
820    * skipping the simcall (for now). It works in parallel, it won't work on
821    * distributed but probably we will change MSG for that. */
822
823   /*
824   smx_simcall_t simcall = simcall_mine();
825   simcall->call = SIMCALL_RDV_GEY_BY_NAME;
826   simcall->rdv_get_by_name.name = name;
827   SIMIX_simcall_push(simcall->issuer);
828   return simcall->rdv_get_by_name.result;*/
829
830   return SIMIX_rdv_get_by_name(name);
831 }
832
833 /**
834  *  \ingroup simix_rdv_management
835  *  \brief Counts the number of communication actions of a given host pending
836  *         on a rendez-vous point.
837  *  \param rdv The rendez-vous point
838  *  \param host The host to be counted
839  *  \return The number of comm actions pending in the rdv
840  */
841 int simcall_rdv_comm_count_by_host(smx_rdv_t rdv, smx_host_t host)
842 {
843   smx_simcall_t simcall = SIMIX_simcall_mine();
844
845   simcall->call = SIMCALL_RDV_COMM_COUNT_BY_HOST;
846   simcall->rdv_comm_count_by_host.rdv = rdv;
847   simcall->rdv_comm_count_by_host.host = host;
848   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
849     simcall->rdv_comm_count_by_host.result = -1;
850
851   SIMIX_simcall_push(simcall->issuer);
852   return simcall->rdv_comm_count_by_host.result;
853 }
854
855 /**
856  *  \ingroup simix_rdv_management
857  *  \brief returns the communication at the head of the rendez-vous
858  *  \param rdv The rendez-vous point
859  *  \return The communication or NULL if empty
860  */
861 smx_action_t simcall_rdv_get_head(smx_rdv_t rdv)
862 {
863   smx_simcall_t simcall = SIMIX_simcall_mine();
864
865   simcall->call = SIMCALL_RDV_GET_HEAD;
866   simcall->rdv_get_head.rdv = rdv;
867   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
868     simcall->rdv_get_head.result = NULL;
869
870   SIMIX_simcall_push(simcall->issuer);
871   return simcall->rdv_get_head.result;
872 }
873
874 void simcall_rdv_set_receiver(smx_rdv_t rdv , smx_process_t process)
875 {
876   smx_simcall_t simcall = SIMIX_simcall_mine();
877
878   simcall->call = SIMCALL_RDV_SET_RECV;
879   simcall->rdv_set_rcv_proc.rdv = rdv;
880   simcall->rdv_set_rcv_proc.receiver = process;
881
882   SIMIX_simcall_push(simcall->issuer);
883 }
884
885 smx_process_t simcall_rdv_get_receiver(smx_rdv_t rdv)
886 {
887   smx_simcall_t simcall = SIMIX_simcall_mine();
888
889   simcall->call = SIMCALL_RDV_GET_RECV;
890   simcall->rdv_get_rcv_proc.rdv = rdv;
891   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
892     simcall->rdv_get_rcv_proc.result = NULL;
893
894   SIMIX_simcall_push(simcall->issuer);
895   return simcall->rdv_get_rcv_proc.result;
896 }
897
898 /**
899  * \ingroup simix_comm_management
900  */
901 void simcall_comm_send(smx_rdv_t rdv, double task_size, double rate,
902                          void *src_buff, size_t src_buff_size,
903                          int (*match_fun)(void *, void *, smx_action_t), void *data,
904                          double timeout)
905 {
906   /* checking for infinite values */
907   xbt_assert(isfinite(task_size), "task_size is not finite!");
908   xbt_assert(isfinite(rate), "rate is not finite!");
909   xbt_assert(isfinite(timeout), "timeout is not finite!");
910   
911   xbt_assert(rdv, "No rendez-vous point defined for send");
912
913   if (MC_is_active()) {
914     /* the model-checker wants two separate simcalls */
915     smx_action_t comm = simcall_comm_isend(rdv, task_size, rate,
916         src_buff, src_buff_size, match_fun, NULL, data, 0);
917     simcall_comm_wait(comm, timeout);
918   }
919   else {
920     smx_simcall_t simcall = SIMIX_simcall_mine();
921
922     simcall->call = SIMCALL_COMM_SEND;
923     simcall->comm_send.rdv = rdv;
924     simcall->comm_send.task_size = task_size;
925     simcall->comm_send.rate = rate;
926     simcall->comm_send.src_buff = src_buff;
927     simcall->comm_send.src_buff_size = src_buff_size;
928     simcall->comm_send.match_fun = match_fun;
929     simcall->comm_send.data = data;
930     simcall->comm_send.timeout = timeout;
931
932     SIMIX_simcall_push(simcall->issuer);
933   }
934 }
935 /**
936  * \ingroup simix_comm_management
937  */
938 smx_action_t simcall_comm_isend(smx_rdv_t rdv, double task_size, double rate,
939                               void *src_buff, size_t src_buff_size,
940                               int (*match_fun)(void *, void *, smx_action_t),
941                               void (*clean_fun)(void *),
942                               void *data,
943                               int detached)
944 {
945   /* checking for infinite values */
946   xbt_assert(isfinite(task_size), "task_size is not finite!");
947   xbt_assert(isfinite(rate), "rate is not finite!");
948   
949   xbt_assert(rdv, "No rendez-vous point defined for isend");
950
951   smx_simcall_t simcall = SIMIX_simcall_mine();
952
953   simcall->call = SIMCALL_COMM_ISEND;
954   simcall->comm_isend.rdv = rdv;
955   simcall->comm_isend.task_size = task_size;
956   simcall->comm_isend.rate = rate;
957   simcall->comm_isend.src_buff = src_buff;
958   simcall->comm_isend.src_buff_size = src_buff_size;
959   simcall->comm_isend.match_fun = match_fun;
960   simcall->comm_isend.clean_fun = clean_fun;
961   simcall->comm_isend.data = data;
962   simcall->comm_isend.detached = detached;
963   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
964     simcall->comm_isend.result = NULL;
965
966   SIMIX_simcall_push(simcall->issuer);
967   return simcall->comm_isend.result;
968 }
969 /**
970  * \ingroup simix_comm_management
971  */
972 void simcall_comm_recv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
973                          int (*match_fun)(void *, void *, smx_action_t), void *data, double timeout)
974 {
975   xbt_assert(isfinite(timeout), "timeout is not finite!");
976   xbt_assert(rdv, "No rendez-vous point defined for recv");
977
978   if (MC_is_active()) {
979     /* the model-checker wants two separate simcalls */
980     smx_action_t comm = simcall_comm_irecv(rdv, dst_buff, dst_buff_size,
981         match_fun, data);
982     simcall_comm_wait(comm, timeout);
983   }
984   else {
985     smx_simcall_t simcall = SIMIX_simcall_mine();
986
987     simcall->call = SIMCALL_COMM_RECV;
988     simcall->comm_recv.rdv = rdv;
989     simcall->comm_recv.dst_buff = dst_buff;
990     simcall->comm_recv.dst_buff_size = dst_buff_size;
991     simcall->comm_recv.match_fun = match_fun;
992     simcall->comm_recv.data = data;
993     simcall->comm_recv.timeout = timeout;
994
995     SIMIX_simcall_push(simcall->issuer);
996   }
997 }
998 /**
999  * \ingroup simix_comm_management
1000  */
1001 smx_action_t simcall_comm_irecv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
1002                                   int (*match_fun)(void *, void *, smx_action_t), void *data)
1003 {
1004   xbt_assert(rdv, "No rendez-vous point defined for irecv");
1005
1006   smx_simcall_t simcall = SIMIX_simcall_mine();
1007
1008   simcall->call = SIMCALL_COMM_IRECV;
1009   simcall->comm_irecv.rdv = rdv;
1010   simcall->comm_irecv.dst_buff = dst_buff;
1011   simcall->comm_irecv.dst_buff_size = dst_buff_size;
1012   simcall->comm_irecv.match_fun = match_fun;
1013   simcall->comm_irecv.data = data;
1014   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1015     simcall->comm_irecv.result = NULL;
1016
1017   SIMIX_simcall_push(simcall->issuer);
1018   return simcall->comm_irecv.result;
1019 }
1020
1021
1022 /**
1023  * \ingroup simix_comm_management
1024  */
1025 smx_action_t simcall_comm_iprobe(smx_rdv_t rdv, int src, int tag,
1026                                 int (*match_fun)(void *, void *, smx_action_t), void *data)
1027 {
1028   xbt_assert(rdv, "No rendez-vous point defined for iprobe");
1029
1030   smx_simcall_t simcall = SIMIX_simcall_mine();
1031
1032   simcall->call = SIMCALL_COMM_IPROBE;
1033   simcall->comm_iprobe.rdv = rdv;
1034   simcall->comm_iprobe.src = src;
1035   simcall->comm_iprobe.match_fun = match_fun;
1036   simcall->comm_iprobe.data = data;
1037   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1038     simcall->comm_iprobe.result = NULL;
1039   SIMIX_simcall_push(simcall->issuer);
1040   return simcall->comm_iprobe.result;
1041 }
1042
1043
1044 void simcall_comm_destroy(smx_action_t comm)
1045 {
1046   xbt_assert(comm, "Invalid parameter");
1047
1048   /* FIXME remove this simcall type: comms are auto-destroyed now */
1049
1050   /*
1051   smx_simcall_t simcall = simcall_mine();
1052
1053   simcall->call = SIMCALL_COMM_DESTROY;
1054   simcall->comm_destroy.comm = comm;
1055
1056   SIMIX_simcall_push(simcall->issuer);
1057   */
1058 }
1059 /**
1060  * \ingroup simix_comm_management
1061  */
1062 void simcall_comm_cancel(smx_action_t comm)
1063 {
1064   smx_simcall_t simcall = SIMIX_simcall_mine();
1065
1066   simcall->call = SIMCALL_COMM_CANCEL;
1067   simcall->comm_cancel.comm = comm;
1068
1069   SIMIX_simcall_push(simcall->issuer);
1070 }
1071 /**
1072  * \ingroup simix_comm_management
1073  */
1074 unsigned int simcall_comm_waitany(xbt_dynar_t comms)
1075 {
1076   smx_simcall_t simcall = SIMIX_simcall_mine();
1077
1078   simcall->call = SIMCALL_COMM_WAITANY;
1079   simcall->comm_waitany.comms = comms;
1080   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1081     simcall->comm_waitany.result = -1;
1082
1083   SIMIX_simcall_push(simcall->issuer);
1084   return simcall->comm_waitany.result;
1085 }
1086 /**
1087  * \ingroup simix_comm_management
1088  */
1089 int simcall_comm_testany(xbt_dynar_t comms)
1090 {
1091   smx_simcall_t simcall = SIMIX_simcall_mine();
1092   if (xbt_dynar_is_empty(comms))
1093     return -1;
1094
1095   simcall->call = SIMCALL_COMM_TESTANY;
1096   simcall->comm_testany.comms = comms;
1097     if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1098       simcall->comm_testany.result = -1;
1099
1100   SIMIX_simcall_push(simcall->issuer);
1101   return simcall->comm_testany.result;
1102 }
1103 /**
1104  * \ingroup simix_comm_management
1105  */
1106 void simcall_comm_wait(smx_action_t comm, double timeout)
1107 {
1108   xbt_assert(isfinite(timeout), "timeout is not finite!");
1109   
1110   smx_simcall_t simcall = SIMIX_simcall_mine();
1111
1112   simcall->call = SIMCALL_COMM_WAIT;
1113   simcall->comm_wait.comm = comm;
1114   simcall->comm_wait.timeout = timeout;
1115
1116   SIMIX_simcall_push(simcall->issuer);
1117 }
1118
1119 #ifdef HAVE_TRACING
1120 /**
1121  * \brief Set the category of an action.
1122  *
1123  * This functions changes the category only. It calls a surf function.
1124  * \param execution The execution action
1125  * \param category The tracing category
1126  */
1127 void simcall_set_category(smx_action_t action, const char *category)
1128 {
1129   if (category == NULL) {
1130     return;
1131   }
1132
1133   smx_simcall_t simcall = SIMIX_simcall_mine();
1134
1135   simcall->call = SIMCALL_SET_CATEGORY;
1136   simcall->set_category.action = action;
1137   simcall->set_category.category = category;
1138
1139   SIMIX_simcall_push(simcall->issuer);
1140 }
1141 #endif
1142 /**
1143  * \ingroup simix_comm_management
1144  *
1145  */
1146 int simcall_comm_test(smx_action_t comm)
1147 {
1148   smx_simcall_t simcall = SIMIX_simcall_mine();
1149
1150   simcall->call = SIMCALL_COMM_TEST;
1151   simcall->comm_test.comm = comm;
1152   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1153     simcall->comm_test.result = -1;
1154
1155   SIMIX_simcall_push(simcall->issuer);
1156   return simcall->comm_test.result;
1157 }
1158 /**
1159  * \ingroup simix_comm_management
1160  *
1161  */
1162 double simcall_comm_get_remains(smx_action_t comm)
1163 {
1164   smx_simcall_t simcall = SIMIX_simcall_mine();
1165
1166   simcall->call = SIMCALL_COMM_GET_REMAINS;
1167   simcall->comm_get_remains.comm = comm;
1168   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1169     simcall->comm_get_remains.result = 0.0;
1170
1171   SIMIX_simcall_push(simcall->issuer);
1172   return simcall->comm_get_remains.result;
1173 }
1174 /**
1175  * \ingroup simix_comm_management
1176  *
1177  */
1178 e_smx_state_t simcall_comm_get_state(smx_action_t comm)
1179 {
1180   smx_simcall_t simcall = SIMIX_simcall_mine();
1181
1182   simcall->call = SIMCALL_COMM_GET_STATE;
1183   simcall->comm_get_state.comm = comm;
1184   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1185     simcall->comm_get_state.result = -1;
1186
1187   SIMIX_simcall_push(simcall->issuer);
1188   return simcall->comm_get_state.result;
1189 }
1190 /**
1191  * \ingroup simix_comm_management
1192  *
1193  */
1194 void *simcall_comm_get_src_data(smx_action_t comm)
1195 {
1196   smx_simcall_t simcall = SIMIX_simcall_mine();
1197
1198   simcall->call = SIMCALL_COMM_GET_SRC_DATA;
1199   simcall->comm_get_src_data.comm = comm;
1200   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1201     simcall->comm_get_src_data.result = NULL;
1202
1203   SIMIX_simcall_push(simcall->issuer);
1204   return simcall->comm_get_src_data.result;
1205 }
1206 /**
1207  * \ingroup simix_comm_management
1208  *
1209  */
1210 void *simcall_comm_get_dst_data(smx_action_t comm)
1211 {
1212   smx_simcall_t simcall = SIMIX_simcall_mine();
1213
1214   simcall->call = SIMCALL_COMM_GET_DST_DATA;
1215   simcall->comm_get_dst_data.comm = comm;
1216   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1217     simcall->comm_get_dst_data.result = NULL;
1218
1219   SIMIX_simcall_push(simcall->issuer);
1220   return simcall->comm_get_dst_data.result;
1221 }
1222 /**
1223  * \ingroup simix_comm_management
1224  *
1225  */
1226 smx_process_t simcall_comm_get_src_proc(smx_action_t comm)
1227 {
1228   smx_simcall_t simcall = SIMIX_simcall_mine();
1229
1230   simcall->call = SIMCALL_COMM_GET_SRC_PROC;
1231   simcall->comm_get_src_proc.comm = comm;
1232   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1233     simcall->comm_get_src_proc.result = NULL;
1234
1235   SIMIX_simcall_push(simcall->issuer);
1236   return simcall->comm_get_src_proc.result;
1237 }
1238 /**
1239  * \ingroup simix_comm_management
1240  *
1241  */
1242 smx_process_t simcall_comm_get_dst_proc(smx_action_t comm)
1243 {
1244   smx_simcall_t simcall = SIMIX_simcall_mine();
1245
1246   simcall->call = SIMCALL_COMM_GET_DST_PROC;
1247   simcall->comm_get_dst_proc.comm = comm;
1248   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1249     simcall->comm_get_dst_proc.result = NULL;
1250
1251   SIMIX_simcall_push(simcall->issuer);
1252   return simcall->comm_get_dst_proc.result;
1253 }
1254
1255 #ifdef HAVE_LATENCY_BOUND_TRACKING
1256 int simcall_comm_is_latency_bounded(smx_action_t comm)
1257 {
1258   smx_simcall_t simcall = SIMIX_simcall_mine();
1259
1260   simcall->call = SIMCALL_COMM_IS_LATENCY_BOUNDED;
1261   simcall->comm_is_latency_bounded.comm = comm;
1262   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1263     simcall->comm_is_latency_bounded.result = -1;
1264
1265   SIMIX_simcall_push(simcall->issuer);
1266   return simcall->comm_is_latency_bounded.result;
1267 }
1268 #endif
1269 /**
1270  * \ingroup simix_synchro_management
1271  *
1272  */
1273 smx_mutex_t simcall_mutex_init(void)
1274 {
1275   if(!simix_global) {
1276     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
1277     xbt_abort();
1278   }
1279   smx_simcall_t simcall = SIMIX_simcall_mine();
1280
1281   simcall->call = SIMCALL_MUTEX_INIT;
1282   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1283     simcall->mutex_init.result = NULL;
1284
1285   SIMIX_simcall_push(simcall->issuer);
1286   return simcall->mutex_init.result;
1287 }
1288 /**
1289  * \ingroup simix_synchro_management
1290  *
1291  */
1292 void simcall_mutex_destroy(smx_mutex_t mutex)
1293 {
1294   smx_simcall_t simcall = SIMIX_simcall_mine();
1295
1296   simcall->call = SIMCALL_MUTEX_DESTROY;
1297   simcall->mutex_destroy.mutex = mutex;
1298
1299   SIMIX_simcall_push(simcall->issuer);
1300 }
1301 /**
1302  * \ingroup simix_synchro_management
1303  *
1304  */
1305 void simcall_mutex_lock(smx_mutex_t mutex)
1306 {
1307   smx_simcall_t simcall = SIMIX_simcall_mine();
1308
1309   simcall->call = SIMCALL_MUTEX_LOCK;
1310   simcall->mutex_lock.mutex = mutex;
1311
1312   SIMIX_simcall_push(simcall->issuer);
1313 }
1314 /**
1315  * \ingroup simix_synchro_management
1316  *
1317  */
1318 int simcall_mutex_trylock(smx_mutex_t mutex)
1319 {
1320   smx_simcall_t simcall = SIMIX_simcall_mine();
1321
1322   simcall->call = SIMCALL_MUTEX_TRYLOCK;
1323   simcall->mutex_trylock.mutex = mutex;
1324   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1325     simcall->mutex_trylock.result = -1;
1326
1327   SIMIX_simcall_push(simcall->issuer);
1328   return simcall->mutex_trylock.result;
1329 }
1330 /**
1331  * \ingroup simix_synchro_management
1332  *
1333  */
1334 void simcall_mutex_unlock(smx_mutex_t mutex)
1335 {
1336   smx_simcall_t simcall = SIMIX_simcall_mine();
1337
1338   simcall->call = SIMCALL_MUTEX_UNLOCK;
1339   simcall->mutex_unlock.mutex = mutex;
1340
1341   SIMIX_simcall_push(simcall->issuer);
1342 }
1343 /**
1344  * \ingroup simix_synchro_management
1345  *
1346  */
1347 smx_cond_t simcall_cond_init(void)
1348 {
1349   smx_simcall_t simcall = SIMIX_simcall_mine();
1350
1351   simcall->call = SIMCALL_COND_INIT;
1352   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1353     simcall->cond_init.result = NULL;
1354
1355   SIMIX_simcall_push(simcall->issuer);
1356   return simcall->cond_init.result;
1357 }
1358 /**
1359  * \ingroup simix_synchro_management
1360  *
1361  */
1362 void simcall_cond_destroy(smx_cond_t cond)
1363 {
1364   smx_simcall_t simcall = SIMIX_simcall_mine();
1365
1366   simcall->call = SIMCALL_COND_DESTROY;
1367   simcall->cond_destroy.cond = cond;
1368
1369   SIMIX_simcall_push(simcall->issuer);
1370 }
1371 /**
1372  * \ingroup simix_synchro_management
1373  *
1374  */
1375 void simcall_cond_signal(smx_cond_t cond)
1376 {
1377   smx_simcall_t simcall = SIMIX_simcall_mine();
1378
1379   simcall->call = SIMCALL_COND_SIGNAL;
1380   simcall->cond_signal.cond = cond;
1381
1382   SIMIX_simcall_push(simcall->issuer);
1383 }
1384 /**
1385  * \ingroup simix_synchro_management
1386  *
1387  */
1388 void simcall_cond_wait(smx_cond_t cond, smx_mutex_t mutex)
1389 {
1390   smx_simcall_t simcall = SIMIX_simcall_mine();
1391
1392   simcall->call = SIMCALL_COND_WAIT;
1393   simcall->cond_wait.cond = cond;
1394   simcall->cond_wait.mutex = mutex;
1395
1396   SIMIX_simcall_push(simcall->issuer);
1397 }
1398 /**
1399  * \ingroup simix_synchro_management
1400  *
1401  */
1402 void simcall_cond_wait_timeout(smx_cond_t cond,
1403                                  smx_mutex_t mutex,
1404                                  double timeout)
1405 {
1406   xbt_assert(isfinite(timeout), "timeout is not finite!");
1407   
1408   smx_simcall_t simcall = SIMIX_simcall_mine();
1409
1410   simcall->call = SIMCALL_COND_WAIT_TIMEOUT;
1411   simcall->cond_wait_timeout.cond = cond;
1412   simcall->cond_wait_timeout.mutex = mutex;
1413   simcall->cond_wait_timeout.timeout = timeout;
1414
1415   SIMIX_simcall_push(simcall->issuer);
1416 }
1417 /**
1418  * \ingroup simix_synchro_management
1419  *
1420  */
1421 void simcall_cond_broadcast(smx_cond_t cond)
1422 {
1423   smx_simcall_t simcall = SIMIX_simcall_mine();
1424
1425   simcall->call = SIMCALL_COND_BROADCAST;
1426   simcall->cond_broadcast.cond = cond;
1427
1428   SIMIX_simcall_push(simcall->issuer);
1429 }
1430 /**
1431  * \ingroup simix_synchro_management
1432  *
1433  */
1434 smx_sem_t simcall_sem_init(int capacity)
1435 {
1436   smx_simcall_t simcall = SIMIX_simcall_mine();
1437
1438   simcall->call = SIMCALL_SEM_INIT;
1439   simcall->sem_init.capacity = capacity;
1440   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1441     simcall->sem_init.result = NULL;
1442
1443   SIMIX_simcall_push(simcall->issuer);
1444   return simcall->sem_init.result;
1445 }
1446 /**
1447  * \ingroup simix_synchro_management
1448  *
1449  */
1450 void simcall_sem_destroy(smx_sem_t sem)
1451 {
1452   smx_simcall_t simcall = SIMIX_simcall_mine();
1453
1454   simcall->call = SIMCALL_SEM_DESTROY;
1455   simcall->sem_destroy.sem = sem;
1456
1457   SIMIX_simcall_push(simcall->issuer);
1458 }
1459 /**
1460  * \ingroup simix_synchro_management
1461  *
1462  */
1463 void simcall_sem_release(smx_sem_t sem)
1464 {
1465   smx_simcall_t simcall = SIMIX_simcall_mine();
1466
1467   simcall->call = SIMCALL_SEM_RELEASE;
1468   simcall->sem_release.sem = sem;
1469
1470   SIMIX_simcall_push(simcall->issuer);
1471 }
1472 /**
1473  * \ingroup simix_synchro_management
1474  *
1475  */
1476 int simcall_sem_would_block(smx_sem_t sem)
1477 {
1478   smx_simcall_t simcall = SIMIX_simcall_mine();
1479
1480   simcall->call = SIMCALL_SEM_WOULD_BLOCK;
1481   simcall->sem_would_block.sem = sem;
1482   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1483     simcall->sem_would_block.result = -1;
1484
1485   SIMIX_simcall_push(simcall->issuer);
1486   return simcall->sem_would_block.result;
1487 }
1488 /**
1489  * \ingroup simix_synchro_management
1490  *
1491  */
1492 void simcall_sem_acquire(smx_sem_t sem)
1493 {
1494   smx_simcall_t simcall = SIMIX_simcall_mine();
1495
1496   simcall->call = SIMCALL_SEM_ACQUIRE;
1497   simcall->sem_acquire.sem = sem;
1498
1499   SIMIX_simcall_push(simcall->issuer);
1500 }
1501 /**
1502  * \ingroup simix_synchro_management
1503  *
1504  */
1505 void simcall_sem_acquire_timeout(smx_sem_t sem, double timeout)
1506 {
1507   xbt_assert(isfinite(timeout), "timeout is not finite!");
1508   
1509   smx_simcall_t simcall = SIMIX_simcall_mine();
1510
1511   simcall->call = SIMCALL_SEM_ACQUIRE_TIMEOUT;
1512   simcall->sem_acquire_timeout.sem = sem;
1513   simcall->sem_acquire_timeout.timeout = timeout;
1514
1515   SIMIX_simcall_push(simcall->issuer);
1516 }
1517 /**
1518  * \ingroup simix_synchro_management
1519  *
1520  */
1521 int simcall_sem_get_capacity(smx_sem_t sem)
1522 {
1523   smx_simcall_t simcall = SIMIX_simcall_mine();
1524
1525   simcall->call = SIMCALL_SEM_GET_CAPACITY;
1526   simcall->sem_get_capacity.sem = sem;
1527   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1528     simcall->sem_get_capacity.result = -1;
1529
1530   SIMIX_simcall_push(simcall->issuer);
1531   return simcall->sem_get_capacity.result;
1532 }
1533 /**
1534  * \ingroup simix_file_management
1535  *
1536  */
1537 double simcall_file_read(void* ptr, size_t size, size_t nmemb, smx_file_t stream)
1538 {
1539   smx_simcall_t simcall = SIMIX_simcall_mine();
1540
1541   simcall->call = SIMCALL_FILE_READ;
1542   simcall->file_read.ptr = ptr;
1543   simcall->file_read.size = size;
1544   simcall->file_read.nmemb = nmemb;
1545   simcall->file_read.stream = stream;
1546   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1547     simcall->file_read.result = 0.0;
1548   SIMIX_simcall_push(simcall->issuer);
1549
1550   return simcall->file_read.result;
1551 }
1552 /**
1553  * \ingroup simix_file_management
1554  *
1555  */
1556 size_t simcall_file_write(const void* ptr, size_t size, size_t nmemb, smx_file_t stream)
1557 {
1558   smx_simcall_t simcall = SIMIX_simcall_mine();
1559
1560   simcall->call = SIMCALL_FILE_WRITE;
1561   simcall->file_write.ptr = ptr;
1562   simcall->file_write.size = size;
1563   simcall->file_write.nmemb = nmemb;
1564   simcall->file_write.stream = stream;
1565   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1566     simcall->file_write.result = 0;
1567   SIMIX_simcall_push(simcall->issuer);
1568
1569   return simcall->file_write.result;
1570 }
1571 /**
1572  * \ingroup simix_file_management
1573  * \brief
1574  */
1575 smx_file_t simcall_file_open(const char* mount, const char* path, const char* mode)
1576 {
1577   smx_simcall_t simcall = SIMIX_simcall_mine();
1578
1579   simcall->call = SIMCALL_FILE_OPEN;
1580   simcall->file_open.mount = mount;
1581   simcall->file_open.path = path;
1582   simcall->file_open.mode = mode;
1583   if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1584     simcall->file_open.result = NULL;
1585   SIMIX_simcall_push(simcall->issuer);
1586
1587   return simcall->file_open.result;
1588 }
1589 /**
1590  * \ingroup simix_file_management
1591  *
1592  */
1593 int simcall_file_close(smx_file_t fp)
1594 {
1595   smx_simcall_t simcall = SIMIX_simcall_mine();
1596
1597   simcall->call = SIMCALL_FILE_CLOSE;
1598   simcall->file_close.fp = fp;
1599   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1600     simcall->file_close.result = -1;
1601   SIMIX_simcall_push(simcall->issuer);
1602
1603   return simcall->file_close.result;
1604 }
1605 /**
1606  * \ingroup simix_file_management
1607  *
1608  */
1609 int simcall_file_stat(smx_file_t fd, s_file_stat_t *buf)
1610 {
1611   smx_simcall_t simcall = SIMIX_simcall_mine();
1612   simcall->call = SIMCALL_FILE_STAT;
1613   simcall->file_stat.fd = fd;
1614   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1615     simcall->file_stat.result = -1;
1616
1617   SIMIX_simcall_push(simcall->issuer);
1618
1619   *buf = simcall->file_stat.buf;
1620
1621   return simcall->file_stat.result;
1622 }
1623
1624 /**
1625  * \ingroup simix_file_management
1626  *
1627  */
1628 int simcall_file_unlink(smx_file_t fd)
1629 {
1630   smx_simcall_t simcall = SIMIX_simcall_mine();
1631   simcall->call = SIMCALL_FILE_UNLINK;
1632   simcall->file_unlink.fd = fd;
1633   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1634     simcall->file_unlink.result = -1;
1635
1636   SIMIX_simcall_push(simcall->issuer);
1637
1638   return simcall->file_unlink.result;
1639 }
1640
1641 /**
1642  * \ingroup simix_file_management
1643  *
1644  */
1645 xbt_dict_t simcall_file_ls(const char* mount, const char* path)
1646 {
1647   smx_simcall_t simcall = SIMIX_simcall_mine();
1648   simcall->call = SIMCALL_FILE_LS;
1649   simcall->file_ls.mount = mount;
1650   simcall->file_ls.path = path;
1651   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1652     simcall->file_ls.result = NULL;
1653
1654   SIMIX_simcall_push(simcall->issuer);
1655
1656   return simcall->file_ls.result;
1657 }
1658
1659 #ifdef HAVE_MC
1660
1661 void *simcall_mc_snapshot(void)
1662 {
1663   smx_simcall_t simcall = SIMIX_simcall_mine();
1664   simcall->call = SIMCALL_MC_SNAPSHOT;
1665   
1666   SIMIX_simcall_push(simcall->issuer);
1667
1668   return simcall->mc_snapshot.s;
1669 }
1670
1671 int simcall_mc_compare_snapshots(void *s1, void *s2){
1672   
1673   smx_simcall_t simcall = SIMIX_simcall_mine();
1674   simcall->call = SIMCALL_MC_COMPARE_SNAPSHOTS;
1675   simcall->mc_compare_snapshots.snapshot1 = s1;
1676   simcall->mc_compare_snapshots.snapshot2 = s2;
1677   
1678   if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1679     simcall->mc_compare_snapshots.result = -1;
1680   
1681   SIMIX_simcall_push(simcall->issuer);
1682   
1683   return simcall->mc_compare_snapshots.result;
1684 }
1685
1686 #endif /* HAVE_MC */
1687
1688 /* ****************************************************************************************** */
1689 /* TUTORIAL: New API                                                                          */
1690 /* All functions for simcall                                                                  */
1691 /* ****************************************************************************************** */
1692 int simcall_new_api_fct(const char* param1, double param2){
1693   smx_simcall_t simcall = SIMIX_simcall_mine();
1694   simcall->call = SIMCALL_NEW_API_INIT;
1695   simcall->new_api.param1 = param1;
1696   simcall->new_api.param2 = param2;
1697
1698   SIMIX_simcall_push(simcall->issuer);
1699   return simcall->new_api.result;
1700 }
1701
1702 /* ************************************************************************** */
1703
1704 /** @brief returns a printable string representing a simcall */
1705 const char *SIMIX_simcall_name(e_smx_simcall_t kind) {
1706   return simcall_names[kind];
1707 }