Logo AND Algorithmique Numérique Distribuée

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