Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
VM: improve error messages, and prefer C++ over MSG
[simgrid.git] / src / simix / libsmx.cpp
1 /* libsmx.c - public interface to simix                                       */
2 /* --------                                                                   */
3 /* These functions are the only ones that are visible from the higher levels  */
4 /* (most of them simply add some documentation to the generated simcall body) */
5 /*                                                                            */
6 /* This is somehow the "libc" of SimGrid                                      */
7
8 /* Copyright (c) 2010-2015. The SimGrid Team.
9  * All rights reserved.                                                     */
10
11 /* This program is free software; you can redistribute it and/or modify it
12  * under the terms of the license (GNU LGPL) which comes with this package. */
13
14 #include <cmath>         /* std::isfinite() */
15
16 #include <functional>
17
18 #include <xbt/functional.hpp>
19
20 #include <simgrid/s4u/VirtualMachine.hpp>
21 #include <simgrid/simix/blocking_simcall.hpp>
22
23 #include "mc/mc.h"
24 #include "smx_private.h"
25 #include "src/kernel/activity/SynchroComm.hpp"
26 #include "src/mc/mc_forward.hpp"
27 #include "src/mc/mc_replay.h"
28 #include "src/plugins/vm/VirtualMachineImpl.hpp"
29 #include "src/simix/smx_host_private.h"
30 #include "xbt/ex.h"
31
32 #include <simgrid/simix.hpp>
33
34 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix);
35
36 #include "popping_bodies.cpp"
37
38 void simcall_call(smx_actor_t process)
39 {
40   if (process != simix_global->maestro_process) {
41     XBT_DEBUG("Yield process '%s' on simcall %s (%d)", process->name.c_str(),
42               SIMIX_simcall_name(process->simcall.call), (int)process->simcall.call);
43     SIMIX_process_yield(process);
44   } else {
45     SIMIX_simcall_handle(&process->simcall, 0);
46   }
47 }
48
49 // ***** AS simcalls
50
51 /**
52  * \ingroup simix_host_management
53  * \brief Returns a dict of the properties assigned to a router or AS.
54  *
55  * \param name The name of the router or AS
56  * \return The properties
57  */
58 xbt_dict_t simcall_asr_get_properties(const char *name)
59 {
60   return simcall_BODY_asr_get_properties(name);
61 }
62
63 /**
64  * \ingroup simix_process_management
65  * \brief Creates a synchro that executes some computation of an host.
66  *
67  * This function creates a SURF action and allocates the data necessary
68  * to create the SIMIX synchro. It can raise a host_error exception if the host crashed.
69  *
70  * \param name Name of the execution synchro to create
71  * \param flops_amount amount Computation amount (in flops)
72  * \param priority computation priority
73  * \param bound
74  * \return A new SIMIX execution synchronization
75  */
76 smx_activity_t simcall_execution_start(const char *name,
77                                     double flops_amount,
78                                     double priority, double bound)
79 {
80   /* checking for infinite values */
81   xbt_assert(std::isfinite(flops_amount), "flops_amount is not finite!");
82   xbt_assert(std::isfinite(priority), "priority is not finite!");
83
84   return simcall_BODY_execution_start(name, flops_amount, priority, bound);
85 }
86
87 /**
88  * \ingroup simix_process_management
89  * \brief Creates a synchro that may involve parallel computation on
90  * several hosts and communication between them.
91  *
92  * \param name Name of the execution synchro to create
93  * \param host_nb Number of hosts where the synchro will be executed
94  * \param host_list Array (of size host_nb) of hosts where the synchro will be executed
95  * \param flops_amount Array (of size host_nb) of computation amount of hosts (in bytes)
96  * \param bytes_amount Array (of size host_nb * host_nb) representing the communication
97  * amount between each pair of hosts
98  * \param amount the SURF action amount
99  * \param rate the SURF action rate
100  * \param timeout timeout
101  * \return A new SIMIX execution synchronization
102  */
103 smx_activity_t simcall_execution_parallel_start(const char* name, int host_nb, sg_host_t* host_list,
104                                                 double* flops_amount, double* bytes_amount, double amount, double rate,
105                                                 double timeout)
106 {
107   int i,j;
108   /* checking for infinite values */
109   for (i = 0 ; i < host_nb ; ++i) {
110     xbt_assert(std::isfinite(flops_amount[i]), "flops_amount[%d] is not finite!", i);
111     if (bytes_amount != nullptr) {
112       for (j = 0 ; j < host_nb ; ++j) {
113         xbt_assert(std::isfinite(bytes_amount[i + host_nb * j]),
114                    "bytes_amount[%d+%d*%d] is not finite!", i, host_nb, j);
115       }
116     }
117   }
118
119   xbt_assert(std::isfinite(amount), "amount is not finite!");
120   xbt_assert(std::isfinite(rate), "rate is not finite!");
121
122   return simcall_BODY_execution_parallel_start(name, host_nb, host_list, flops_amount, bytes_amount, amount, rate,
123                                                timeout);
124 }
125
126 /**
127  * \ingroup simix_process_management
128  * \brief Cancels an execution synchro.
129  *
130  * This functions stops the execution. It calls a surf function.
131  * \param execution The execution synchro to cancel
132  */
133 void simcall_execution_cancel(smx_activity_t execution)
134 {
135   simcall_BODY_execution_cancel(execution);
136 }
137
138 /**
139  * \ingroup simix_process_management
140  * \brief Changes the priority of an execution synchro.
141  *
142  * This functions changes the priority only. It calls a surf function.
143  * \param execution The execution synchro
144  * \param priority The new priority
145  */
146 void simcall_execution_set_priority(smx_activity_t execution, double priority)
147 {
148   /* checking for infinite values */
149   xbt_assert(std::isfinite(priority), "priority is not finite!");
150
151   simcall_BODY_execution_set_priority(execution, priority);
152 }
153
154 /**
155  * \ingroup simix_process_management
156  * \brief Changes the capping (the maximum CPU utilization) of an execution synchro.
157  *
158  * This functions changes the capping only. It calls a surf function.
159  * \param execution The execution synchro
160  * \param bound The new bound
161  */
162 void simcall_execution_set_bound(smx_activity_t execution, double bound)
163 {
164   simcall_BODY_execution_set_bound(execution, bound);
165 }
166
167 /**
168  * \ingroup simix_host_management
169  * \brief Waits for the completion of an execution synchro and destroy it.
170  *
171  * \param execution The execution synchro
172  */
173 e_smx_state_t simcall_execution_wait(smx_activity_t execution)
174 {
175   return (e_smx_state_t) simcall_BODY_execution_wait(execution);
176 }
177
178 /**
179  * \ingroup simix_vm_management
180  * \brief Start the given VM to the given physical host
181  *
182  * \param vm VM
183  */
184 void simcall_vm_start(sg_host_t vm)
185 {
186   simgrid::simix::kernelImmediate(std::bind(SIMIX_vm_start, vm));
187 }
188
189 /**
190  * @brief Function to set the CPU bound of the given SIMIX VM host.
191  *
192  * @param host the vm host (a sg_host_t)
193  * @param bound bound (a double)
194  */
195 void simcall_vm_set_bound(sg_host_t vm, double bound)
196 {
197   simgrid::simix::kernelImmediate(
198       [vm, bound]() { static_cast<simgrid::s4u::VirtualMachine*>(vm)->pimpl_vm_->setBound(bound); });
199 }
200
201 /**
202  * \ingroup simix_vm_management
203  * \brief Suspend the given VM
204  *
205  * \param vm VM
206  */
207 void simcall_vm_suspend(sg_host_t vm)
208 {
209   simcall_BODY_vm_suspend(vm);
210 }
211
212 /**
213  * \ingroup simix_vm_management
214  * \brief Resume the given VM
215  *
216  * \param vm VM
217  */
218 void simcall_vm_resume(sg_host_t vm)
219 {
220   simcall_BODY_vm_resume(vm);
221 }
222
223 /**
224  * \ingroup simix_vm_management
225  * \brief Save the given VM
226  *
227  * \param vm VM
228  */
229 void simcall_vm_save(sg_host_t vm)
230 {
231   simcall_BODY_vm_save(vm);
232 }
233
234 /**
235  * \ingroup simix_vm_management
236  * \brief Restore the given VM
237  *
238  * \param vm VM
239  */
240 void simcall_vm_restore(sg_host_t vm)
241 {
242   simgrid::simix::kernelImmediate([vm]() {
243     if (static_cast<simgrid::s4u::VirtualMachine*>(vm)->pimpl_vm_->getState() != SURF_VM_STATE_SAVED)
244       THROWF(vm_error, 0, "VM(%s) was not saved", vm->name().c_str());
245
246     XBT_DEBUG("restore VM(%s), where %d processes exist", vm->name().c_str(),
247               xbt_swag_size(sg_host_simix(vm)->process_list));
248
249     /* jump to vm_ws_restore() */
250     static_cast<simgrid::s4u::VirtualMachine*>(vm)->pimpl_vm_->restore();
251
252     smx_actor_t smx_process, smx_process_safe;
253     xbt_swag_foreach_safe(smx_process, smx_process_safe, sg_host_simix(vm)->process_list)
254     {
255       XBT_DEBUG("resume %s", smx_process->name.c_str());
256       SIMIX_process_resume(smx_process);
257     }
258   });
259 }
260
261 /**
262  * \ingroup simix_vm_management
263  * \brief Shutdown the given VM
264  *
265  * \param vm VM
266  */
267 void simcall_vm_shutdown(sg_host_t vm)
268 {
269   simcall_BODY_vm_shutdown(vm);
270 }
271
272 /**
273  * \ingroup simix_process_management
274  * \brief Kills a SIMIX process.
275  *
276  * This function simply kills a  process.
277  *
278  * \param process poor victim
279  */
280 void simcall_process_kill(smx_actor_t process)
281 {
282   simcall_BODY_process_kill(process);
283 }
284
285 /**
286  * \ingroup simix_process_management
287  * \brief Kills all SIMIX processes.
288  */
289 void simcall_process_killall(int reset_pid)
290 {
291   simcall_BODY_process_killall(reset_pid);
292 }
293
294 /**
295  * \ingroup simix_process_management
296  * \brief Cleans up a SIMIX process.
297  * \param process poor victim (must have already been killed)
298  */
299 void simcall_process_cleanup(smx_actor_t process)
300 {
301   simcall_BODY_process_cleanup(process);
302 }
303
304 /**
305  * \ingroup simix_process_management
306  * \brief Migrates an agent to another location.
307  *
308  * This function changes the value of the host on which \a process is running.
309  *
310  * \param process the process to migrate
311  * \param dest name of the new host
312  */
313 void simcall_process_set_host(smx_actor_t process, sg_host_t dest)
314 {
315   simcall_BODY_process_set_host(process, dest);
316 }
317
318 void simcall_process_join(smx_actor_t process, double timeout)
319 {
320   simcall_BODY_process_join(process, timeout);
321 }
322
323 /**
324  * \ingroup simix_process_management
325  * \brief Suspends a process.
326  *
327  * This function suspends the process by suspending the synchro
328  * it was waiting for completion.
329  *
330  * \param process a SIMIX process
331  */
332 void simcall_process_suspend(smx_actor_t process)
333 {
334   simcall_BODY_process_suspend(process);
335 }
336
337 /**
338  * \ingroup simix_process_management
339  * \brief Resumes a suspended process.
340  *
341  * This function resumes a suspended process by resuming the synchro
342  * it was waiting for completion.
343  *
344  * \param process a SIMIX process
345  */
346 void simcall_process_resume(smx_actor_t process)
347 {
348   simcall_BODY_process_resume(process);
349 }
350
351 /**
352  * \ingroup simix_process_management
353  * \brief Returns the amount of SIMIX processes in the system
354  *
355  * Maestro internal process is not counted, only user code processes are
356  */
357 int simcall_process_count()
358 {
359   return simgrid::simix::kernelImmediate(SIMIX_process_count);
360 }
361
362 /**
363  * \ingroup simix_process_management
364  * \brief Return the user data of a #smx_actor_t.
365  * \param process a SIMIX process
366  * \return the user data of this process
367  */
368 void* simcall_process_get_data(smx_actor_t process)
369 {
370   return SIMIX_process_get_data(process);
371 }
372
373 /**
374  * \ingroup simix_process_management
375  * \brief Set the user data of a #smx_actor_t.
376  *
377  * This functions sets the user data associated to \a process.
378  * \param process SIMIX process
379  * \param data User data
380  */
381 void simcall_process_set_data(smx_actor_t process, void *data)
382 {
383   simgrid::simix::kernelImmediate(std::bind(SIMIX_process_set_data, process, data));
384 }
385
386 /**
387  * \ingroup simix_process_management
388  * \brief Set the kill time of a process.
389  */
390 void simcall_process_set_kill_time(smx_actor_t process, double kill_time)
391 {
392
393   if (kill_time <= SIMIX_get_clock() || simix_global->kill_process_function == nullptr)
394     return;
395   XBT_DEBUG("Set kill time %f for process %s(%s)",
396     kill_time, process->name.c_str(), sg_host_get_name(process->host));
397   process->kill_timer = SIMIX_timer_set(kill_time, [=] {
398     simix_global->kill_process_function(process);
399     process->kill_timer=nullptr;
400   });
401 }
402 /**
403  * \ingroup simix_process_management
404  * \brief Get the kill time of a process (or 0 if unset).
405  */
406 double simcall_process_get_kill_time(smx_actor_t process) {
407   return SIMIX_timer_get_date(process->kill_timer);
408 }
409
410 /**
411  * \ingroup simix_process_management
412  * \brief Returns true if the process is suspended .
413  *
414  * This checks whether a process is suspended or not by inspecting the task on which it was waiting for the completion.
415  * \param process SIMIX process
416  * \return 1, if the process is suspended, else 0.
417  */
418 int simcall_process_is_suspended(smx_actor_t process)
419 {
420   return simcall_BODY_process_is_suspended(process);
421 }
422
423 /**
424  * \ingroup simix_process_management
425  * \brief Return the properties
426  *
427  * This functions returns the properties associated with this process
428  */
429 xbt_dict_t simcall_process_get_properties(smx_actor_t process)
430 {
431   return SIMIX_process_get_properties(process);
432 }
433 /**
434  * \ingroup simix_process_management
435  * \brief Add an on_exit function
436  * Add an on_exit function which will be executed when the process exits/is killed.
437  */
438 XBT_PUBLIC(void) simcall_process_on_exit(smx_actor_t process, int_f_pvoid_pvoid_t fun, void *data)
439 {
440   simcall_BODY_process_on_exit(process, fun, data);
441 }
442 /**
443  * \ingroup simix_process_management
444  * \brief Sets the process to be auto-restarted or not by SIMIX when its host comes back up.
445  * Will restart the process when the host comes back up if auto_restart is set to 1.
446  */
447
448 XBT_PUBLIC(void) simcall_process_auto_restart_set(smx_actor_t process, int auto_restart)
449 {
450   simcall_BODY_process_auto_restart_set(process, auto_restart);
451 }
452
453 /**
454  * \ingroup simix_process_management
455  * \brief Restarts the process, killing it and starting it again from scratch.
456  */
457 XBT_PUBLIC(smx_actor_t) simcall_process_restart(smx_actor_t process)
458 {
459   return (smx_actor_t) simcall_BODY_process_restart(process);
460 }
461 /**
462  * \ingroup simix_process_management
463  * \brief Creates a new sleep SIMIX synchro.
464  *
465  * This function creates a SURF action and allocates the data necessary
466  * to create the SIMIX synchro. It can raise a host_error exception if the
467  * host crashed. The default SIMIX name of the synchro is "sleep".
468  *
469  *   \param duration Time duration of the sleep.
470  *   \return A result telling whether the sleep was successful
471  */
472 e_smx_state_t simcall_process_sleep(double duration)
473 {
474   /* checking for infinite values */
475   xbt_assert(std::isfinite(duration), "duration is not finite!");
476   return (e_smx_state_t) simcall_BODY_process_sleep(duration);
477 }
478
479 /**
480  *  \ingroup simix_mbox_management
481  *  \brief Creates a new rendez-vous point
482  *  \param name The name of the rendez-vous point
483  *  \return The created rendez-vous point
484  */
485 smx_mailbox_t simcall_mbox_create(const char *name)
486 {
487   return simcall_BODY_mbox_create(name);
488 }
489
490 void simcall_mbox_set_receiver(smx_mailbox_t mbox, smx_actor_t process)
491 {
492   simcall_BODY_mbox_set_receiver(mbox, process);
493 }
494
495 /**
496  * \ingroup simix_comm_management
497  */
498 void simcall_comm_send(smx_actor_t sender, smx_mailbox_t mbox, double task_size, double rate,
499                          void *src_buff, size_t src_buff_size,
500                          int (*match_fun)(void *, void *, smx_activity_t),
501                          void (*copy_data_fun)(smx_activity_t, void*, size_t), void *data,
502                          double timeout)
503 {
504   /* checking for infinite values */
505   xbt_assert(std::isfinite(task_size), "task_size is not finite!");
506   xbt_assert(std::isfinite(rate), "rate is not finite!");
507   xbt_assert(std::isfinite(timeout), "timeout is not finite!");
508
509   xbt_assert(mbox, "No rendez-vous point defined for send");
510
511   if (MC_is_active() || MC_record_replay_is_active()) {
512     /* the model-checker wants two separate simcalls */
513     smx_activity_t comm = nullptr; /* MC needs the comm to be set to nullptr during the simcall */
514     comm = simcall_comm_isend(sender, mbox, task_size, rate,
515         src_buff, src_buff_size, match_fun, nullptr, copy_data_fun, data, 0);
516     simcall_comm_wait(comm, timeout);
517     comm = nullptr;
518   }
519   else {
520     simcall_BODY_comm_send(sender, mbox, task_size, rate, src_buff, src_buff_size,
521                          match_fun, copy_data_fun, data, timeout);
522   }
523 }
524
525 /**
526  * \ingroup simix_comm_management
527  */
528 smx_activity_t simcall_comm_isend(smx_actor_t sender, smx_mailbox_t mbox, double task_size, double rate,
529                               void *src_buff, size_t src_buff_size,
530                               int (*match_fun)(void *, void *, smx_activity_t),
531                               void (*clean_fun)(void *),
532                               void (*copy_data_fun)(smx_activity_t, void*, size_t),
533                               void *data,
534                               int detached)
535 {
536   /* checking for infinite values */
537   xbt_assert(std::isfinite(task_size), "task_size is not finite!");
538   xbt_assert(std::isfinite(rate), "rate is not finite!");
539
540   xbt_assert(mbox, "No rendez-vous point defined for isend");
541
542   return simcall_BODY_comm_isend(sender, mbox, task_size, rate, src_buff,
543                                  src_buff_size, match_fun,
544                                  clean_fun, copy_data_fun, data, detached);
545 }
546
547 /**
548  * \ingroup simix_comm_management
549  */
550 void simcall_comm_recv(smx_actor_t receiver, smx_mailbox_t mbox, void *dst_buff, size_t * dst_buff_size,
551                        int (*match_fun)(void *, void *, smx_activity_t),
552                        void (*copy_data_fun)(smx_activity_t, void*, size_t),
553                        void *data, double timeout, double rate)
554 {
555   xbt_assert(std::isfinite(timeout), "timeout is not finite!");
556   xbt_assert(mbox, "No rendez-vous point defined for recv");
557
558   if (MC_is_active() || MC_record_replay_is_active()) {
559     /* the model-checker wants two separate simcalls */
560     smx_activity_t comm = nullptr; /* MC needs the comm to be set to nullptr during the simcall */
561     comm = simcall_comm_irecv(receiver, mbox, dst_buff, dst_buff_size,
562                               match_fun, copy_data_fun, data, rate);
563     simcall_comm_wait(comm, timeout);
564     comm = nullptr;
565   }
566   else {
567     simcall_BODY_comm_recv(receiver, mbox, dst_buff, dst_buff_size,
568                            match_fun, copy_data_fun, data, timeout, rate);
569   }
570 }
571 /**
572  * \ingroup simix_comm_management
573  */
574 smx_activity_t simcall_comm_irecv(smx_actor_t receiver, smx_mailbox_t mbox, void *dst_buff, size_t *dst_buff_size,
575                                 int (*match_fun)(void *, void *, smx_activity_t),
576                                 void (*copy_data_fun)(smx_activity_t, void*, size_t),
577                                 void *data, double rate)
578 {
579   xbt_assert(mbox, "No rendez-vous point defined for irecv");
580
581   return simcall_BODY_comm_irecv(receiver, mbox, dst_buff, dst_buff_size,
582                                  match_fun, copy_data_fun, data, rate);
583 }
584
585 /**
586  * \ingroup simix_comm_management
587  */
588 smx_activity_t simcall_comm_iprobe(smx_mailbox_t mbox, int type, int src, int tag,
589                                 int (*match_fun)(void *, void *, smx_activity_t), void *data)
590 {
591   xbt_assert(mbox, "No rendez-vous point defined for iprobe");
592
593   return simcall_BODY_comm_iprobe(mbox, type, src, tag, match_fun, data);
594 }
595
596 /**
597  * \ingroup simix_comm_management
598  */
599 void simcall_comm_cancel(smx_activity_t synchro)
600 {
601   simgrid::simix::kernelImmediate([synchro]{
602     simgrid::kernel::activity::Comm *comm = static_cast<simgrid::kernel::activity::Comm*>(synchro);
603     comm->cancel();
604   });
605 }
606
607 /**
608  * \ingroup simix_comm_management
609  */
610 unsigned int simcall_comm_waitany(xbt_dynar_t comms, double timeout)
611 {
612   return simcall_BODY_comm_waitany(comms, timeout);
613 }
614
615 /**
616  * \ingroup simix_comm_management
617  */
618 int simcall_comm_testany(smx_activity_t* comms, size_t count)
619 {
620   if (count == 0)
621     return -1;
622   return simcall_BODY_comm_testany(comms, count);
623 }
624
625 /**
626  * \ingroup simix_comm_management
627  */
628 void simcall_comm_wait(smx_activity_t comm, double timeout)
629 {
630   xbt_assert(std::isfinite(timeout), "timeout is not finite!");
631   simcall_BODY_comm_wait(comm, timeout);
632 }
633
634 /**
635  * \brief Set the category of an synchro.
636  *
637  * This functions changes the category only. It calls a surf function.
638  * \param execution The execution synchro
639  * \param category The tracing category
640  */
641 void simcall_set_category(smx_activity_t synchro, const char *category)
642 {
643   if (category == nullptr) {
644     return;
645   }
646   simcall_BODY_set_category(synchro, category);
647 }
648
649 /**
650  * \ingroup simix_comm_management
651  *
652  */
653 int simcall_comm_test(smx_activity_t comm)
654 {
655   return simcall_BODY_comm_test(comm);
656 }
657
658 /**
659  * \ingroup simix_synchro_management
660  *
661  */
662 smx_mutex_t simcall_mutex_init()
663 {
664   if(!simix_global) {
665     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
666     xbt_abort();
667   }
668   return simcall_BODY_mutex_init();
669 }
670
671 /**
672  * \ingroup simix_synchro_management
673  *
674  */
675 void simcall_mutex_lock(smx_mutex_t mutex)
676 {
677   simcall_BODY_mutex_lock(mutex);
678 }
679
680 /**
681  * \ingroup simix_synchro_management
682  *
683  */
684 int simcall_mutex_trylock(smx_mutex_t mutex)
685 {
686   return simcall_BODY_mutex_trylock(mutex);
687 }
688
689 /**
690  * \ingroup simix_synchro_management
691  *
692  */
693 void simcall_mutex_unlock(smx_mutex_t mutex)
694 {
695   simcall_BODY_mutex_unlock(mutex);
696 }
697
698 /**
699  * \ingroup simix_synchro_management
700  *
701  */
702 smx_cond_t simcall_cond_init()
703 {
704   return simcall_BODY_cond_init();
705 }
706
707 /**
708  * \ingroup simix_synchro_management
709  *
710  */
711 void simcall_cond_signal(smx_cond_t cond)
712 {
713   simcall_BODY_cond_signal(cond);
714 }
715
716 /**
717  * \ingroup simix_synchro_management
718  *
719  */
720 void simcall_cond_wait(smx_cond_t cond, smx_mutex_t mutex)
721 {
722   simcall_BODY_cond_wait(cond, mutex);
723 }
724
725 /**
726  * \ingroup simix_synchro_management
727  *
728  */
729 void simcall_cond_wait_timeout(smx_cond_t cond,
730                                  smx_mutex_t mutex,
731                                  double timeout)
732 {
733   xbt_assert(std::isfinite(timeout), "timeout is not finite!");
734   simcall_BODY_cond_wait_timeout(cond, mutex, timeout);
735 }
736
737 /**
738  * \ingroup simix_synchro_management
739  *
740  */
741 void simcall_cond_broadcast(smx_cond_t cond)
742 {
743   simcall_BODY_cond_broadcast(cond);
744 }
745
746 /**
747  * \ingroup simix_synchro_management
748  *
749  */
750 smx_sem_t simcall_sem_init(int capacity)
751 {
752   return simcall_BODY_sem_init(capacity);
753 }
754
755 /**
756  * \ingroup simix_synchro_management
757  *
758  */
759 void simcall_sem_release(smx_sem_t sem)
760 {
761   simcall_BODY_sem_release(sem);
762 }
763
764 /**
765  * \ingroup simix_synchro_management
766  *
767  */
768 int simcall_sem_would_block(smx_sem_t sem)
769 {
770   return simcall_BODY_sem_would_block(sem);
771 }
772
773 /**
774  * \ingroup simix_synchro_management
775  *
776  */
777 void simcall_sem_acquire(smx_sem_t sem)
778 {
779   simcall_BODY_sem_acquire(sem);
780 }
781
782 /**
783  * \ingroup simix_synchro_management
784  *
785  */
786 void simcall_sem_acquire_timeout(smx_sem_t sem, double timeout)
787 {
788   xbt_assert(std::isfinite(timeout), "timeout is not finite!");
789   simcall_BODY_sem_acquire_timeout(sem, timeout);
790 }
791
792 /**
793  * \ingroup simix_synchro_management
794  *
795  */
796 int simcall_sem_get_capacity(smx_sem_t sem)
797 {
798   return simcall_BODY_sem_get_capacity(sem);
799 }
800
801 /**
802  * \ingroup simix_file_management
803  *
804  */
805 sg_size_t simcall_file_read(smx_file_t fd, sg_size_t size, sg_host_t host)
806 {
807   return simcall_BODY_file_read(fd, size, host);
808 }
809
810 /**
811  * \ingroup simix_file_management
812  *
813  */
814 sg_size_t simcall_file_write(smx_file_t fd, sg_size_t size, sg_host_t host)
815 {
816   return simcall_BODY_file_write(fd, size, host);
817 }
818
819 /**
820  * \ingroup simix_file_management
821  * \brief
822  */
823 smx_file_t simcall_file_open(const char* fullpath, sg_host_t host)
824 {
825   return simcall_BODY_file_open(fullpath, host);
826 }
827
828 /**
829  * \ingroup simix_file_management
830  *
831  */
832 int simcall_file_close(smx_file_t fd, sg_host_t host)
833 {
834   return simcall_BODY_file_close(fd, host);
835 }
836
837 /**
838  * \ingroup simix_file_management
839  *
840  */
841 int simcall_file_unlink(smx_file_t fd, sg_host_t host)
842 {
843   return simcall_BODY_file_unlink(fd, host);
844 }
845
846 /**
847  * \ingroup simix_file_management
848  *
849  */
850 sg_size_t simcall_file_get_size(smx_file_t fd){
851   return simcall_BODY_file_get_size(fd);
852 }
853
854 /**
855  * \ingroup simix_file_management
856  *
857  */
858 sg_size_t simcall_file_tell(smx_file_t fd){
859   return simcall_BODY_file_tell(fd);
860 }
861
862 /**
863  * \ingroup simix_file_management
864  *
865  */
866 xbt_dynar_t simcall_file_get_info(smx_file_t fd)
867 {
868   return simcall_BODY_file_get_info(fd);
869 }
870
871 /**
872  * \ingroup simix_file_management
873  *
874  */
875 int simcall_file_seek(smx_file_t fd, sg_offset_t offset, int origin){
876   return simcall_BODY_file_seek(fd, offset, origin);
877 }
878
879 /**
880  * \ingroup simix_file_management
881  * \brief Move a file to another location on the *same mount point*.
882  *
883  */
884 int simcall_file_move(smx_file_t fd, const char* fullpath)
885 {
886   return simcall_BODY_file_move(fd, fullpath);
887 }
888
889 /**
890  * \ingroup simix_storage_management
891  * \brief Returns the free space size on a given storage element.
892  * \param storage a storage
893  * \return Return the free space size on a given storage element (as sg_size_t)
894  */
895 sg_size_t simcall_storage_get_free_size (smx_storage_t storage){
896   return simcall_BODY_storage_get_free_size(storage);
897 }
898
899 /**
900  * \ingroup simix_storage_management
901  * \brief Returns the used space size on a given storage element.
902  * \param storage a storage
903  * \return Return the used space size on a given storage element (as sg_size_t)
904  */
905 sg_size_t simcall_storage_get_used_size (smx_storage_t storage){
906   return simcall_BODY_storage_get_used_size(storage);
907 }
908
909 /**
910  * \ingroup simix_storage_management
911  * \brief Returns a dict of the properties assigned to a storage element.
912  *
913  * \param storage A storage element
914  * \return The properties of this storage element
915  */
916 xbt_dict_t simcall_storage_get_properties(smx_storage_t storage)
917 {
918   return simcall_BODY_storage_get_properties(storage);
919 }
920
921 /**
922  * \ingroup simix_storage_management
923  * \brief Returns a dict containing the content of a storage element.
924  *
925  * \param storage A storage element
926  * \return The content of this storage element as a dict (full path file => size)
927  */
928 xbt_dict_t simcall_storage_get_content(smx_storage_t storage)
929 {
930   return simcall_BODY_storage_get_content(storage);
931 }
932
933 void simcall_run_kernel(std::function<void()> const& code)
934 {
935   simcall_BODY_run_kernel(&code);
936 }
937
938 void simcall_run_blocking(std::function<void()> const& code)
939 {
940   simcall_BODY_run_blocking(&code);
941 }
942
943 int simcall_mc_random(int min, int max) {
944   return simcall_BODY_mc_random(min, max);
945 }
946
947 /* ************************************************************************** */
948
949 /** @brief returns a printable string representing a simcall */
950 const char *SIMIX_simcall_name(e_smx_simcall_t kind) {
951   return simcall_names[kind];
952 }
953
954 namespace simgrid {
955 namespace simix {
956
957 void unblock(smx_actor_t process)
958 {
959   xbt_assert(SIMIX_is_maestro());
960   SIMIX_simcall_answer(&process->simcall);
961 }
962
963 }
964 }