Logo AND Algorithmique Numérique Distribuée

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