1 /* smx_user.c - public interface to simix */
3 /* Copyright (c) 2010-2012. Da SimGrid team. All rights reserved. */
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. */
8 #include "smx_private.h"
11 #include <math.h> /* isfinite() */
13 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix);
15 /* generate strings from the enumeration values */
16 static const char* simcall_names[] = {
17 SIMCALL_LIST(SIMCALL_STRING_TYPE, SIMCALL_SEP_COMMA)
18 [SIMCALL_NONE] = "NONE"
21 SIMCALL_LIST(SIMCALL_FUNC, SIMCALL_SEP_NOTHING)
24 * \ingroup simix_host_management
25 * \brief Returns a host given its name.
27 * \param name The name of the host to get
28 * \return The corresponding host
30 smx_host_t simcall_host_get_by_name(const char *name)
32 return simcall_BODY_host_get_by_name(name);
36 * \ingroup simix_host_management
37 * \brief Returns the name of a host.
39 * \param host A SIMIX host
40 * \return The name of this host
42 const char* simcall_host_get_name(smx_host_t host)
44 return simcall_BODY_host_get_name(host);
48 * \ingroup simix_host_management
49 * \brief Returns a dict of the properties assigned to a host.
52 * \return The properties of this host
54 xbt_dict_t simcall_host_get_properties(smx_host_t host)
56 return simcall_BODY_host_get_properties(host);
60 * \ingroup simix_host_management
61 * \brief Returns a dict of the properties assigned to a router or AS.
63 * \param name The name of the router or AS
64 * \return The properties
66 xbt_dict_t simcall_asr_get_properties(const char *name)
68 return simcall_BODY_asr_get_properties(name);
73 * \ingroup simix_host_management
74 * \brief Returns the speed of the processor.
76 * The speed returned does not take into account the current load on the machine.
77 * \param host A SIMIX host
78 * \return The speed of this host (in Mflop/s)
80 double simcall_host_get_speed(smx_host_t host)
82 return simcall_BODY_host_get_speed(host);
86 * \ingroup simix_host_management
87 * \brief Returns the available speed of the processor.
89 * \return Speed currently available (in Mflop/s)
91 double simcall_host_get_available_speed(smx_host_t host)
93 return simcall_BODY_host_get_available_speed(host);
97 * \ingroup simix_host_management
98 * \brief Returns the state of a host.
100 * Two states are possible: 1 if the host is active or 0 if it has crashed.
101 * \param host A SIMIX host
102 * \return 1 if the host is available, 0 otherwise
104 int simcall_host_get_state(smx_host_t host)
106 return simcall_BODY_host_get_state(host);
110 * \ingroup simix_host_management
111 * \brief Returns the user data associated to a host.
113 * \param host SIMIX host
114 * \return the user data of this host
116 void* simcall_host_get_data(smx_host_t host)
118 return simcall_BODY_host_get_data(host);
122 * \ingroup simix_host_management
123 * \brief Sets the user data associated to a host.
125 * The host must not have previous user data associated to it.
126 * \param host A SIMIX host
127 * \param data The user data to set
129 void simcall_host_set_data(smx_host_t host, void *data)
131 simcall_host_set_data(host, data);
135 * \ingroup simix_host_management
136 * \brief Creates an action that executes some computation of an host.
138 * This function creates a SURF action and allocates the data necessary
139 * to create the SIMIX action. It can raise a host_error exception if the host crashed.
141 * \param name Name of the execution action to create
142 * \param host SIMIX host where the action will be executed
143 * \param computation_amount amount Computation amount (in bytes)
144 * \param priority computation priority
145 * \return A new SIMIX execution action
148 smx_action_t simcall_host_execute(const char *name, smx_host_t host,
149 double computation_amount,
152 /* checking for infinite values */
153 xbt_assert(isfinite(computation_amount), "computation_amount is not finite!");
154 xbt_assert(isfinite(priority), "priority is not finite!");
156 return simcall_BODY_host_execute(name, host, computation_amount, priority);
160 * \ingroup simix_host_management
161 * \brief Creates an action that may involve parallel computation on
162 * several hosts and communication between them.
164 * \param name Name of the execution action to create
165 * \param host_nb Number of hosts where the action will be executed
166 * \param host_list Array (of size host_nb) of hosts where the action will be executed
167 * \param computation_amount Array (of size host_nb) of computation amount of hosts (in bytes)
168 * \param communication_amount Array (of size host_nb * host_nb) representing the communication
169 * amount between each pair of hosts
170 * \param amount the SURF action amount
171 * \param rate the SURF action rate
172 * \return A new SIMIX execution action
174 smx_action_t simcall_host_parallel_execute(const char *name,
176 smx_host_t *host_list,
177 double *computation_amount,
178 double *communication_amount,
183 /* checking for infinite values */
184 for (i = 0 ; i < host_nb ; ++i) {
185 xbt_assert(isfinite(computation_amount[i]), "computation_amount[%d] is not finite!", i);
186 for (j = 0 ; j < host_nb ; ++j) {
187 xbt_assert(isfinite(communication_amount[i + host_nb * j]),
188 "communication_amount[%d+%d*%d] is not finite!", i, host_nb, j);
192 xbt_assert(isfinite(amount), "amount is not finite!");
193 xbt_assert(isfinite(rate), "rate is not finite!");
195 return simcall_BODY_host_parallel_execute(name, host_nb, host_list,
197 communication_amount,
203 * \ingroup simix_host_management
204 * \brief Destroys an execution action.
206 * Destroys an action, freing its memory. This function cannot be called if there are a conditional waiting for it.
207 * \param execution The execution action to destroy
209 void simcall_host_execution_destroy(smx_action_t execution)
211 simcall_BODY_host_execution_destroy(execution);
215 * \ingroup simix_host_management
216 * \brief Cancels an execution action.
218 * This functions stops the execution. It calls a surf function.
219 * \param execution The execution action to cancel
221 void simcall_host_execution_cancel(smx_action_t execution)
223 simcall_BODY_host_execution_cancel(execution);
227 * \ingroup simix_host_management
228 * \brief Returns how much of an execution action remains to be done.
230 * \param execution The execution action
231 * \return The remaining amount
233 double simcall_host_execution_get_remains(smx_action_t execution)
235 return simcall_BODY_host_execution_get_remains(execution);
239 * \ingroup simix_host_management
240 * \brief Returns the state of an execution action.
242 * \param execution The execution action
245 e_smx_state_t simcall_host_execution_get_state(smx_action_t execution)
247 return simcall_BODY_host_execution_get_state(execution);
251 * \ingroup simix_host_management
252 * \brief Changes the priority of an execution action.
254 * This functions changes the priority only. It calls a surf function.
255 * \param execution The execution action
256 * \param priority The new priority
258 void simcall_host_execution_set_priority(smx_action_t execution, double priority)
260 /* checking for infinite values */
261 xbt_assert(isfinite(priority), "priority is not finite!");
263 simcall_BODY_host_execution_set_priority(execution, priority);
267 * \ingroup simix_host_management
268 * \brief Waits for the completion of an execution action and destroy it.
270 * \param execution The execution action
272 e_smx_state_t simcall_host_execution_wait(smx_action_t execution)
274 return simcall_BODY_host_execution_wait(execution);
279 * \ingroup simix_vm_management
280 * \brief Create a VM on the given physical host.
282 * \param name VM name
283 * \param host Physical host
285 * \return The host object of the VM
287 void* simcall_vm_create(const char *name, smx_host_t phys_host){
288 /* will jump to SIMIX_pre_vm_create() in src/simix/smx_smurf_private.h */
289 return simcall_BODY_vm_create(name, phys_host);
293 * \ingroup simix_vm_management
294 * \brief Start the given VM to the given physical host
298 void simcall_vm_start(smx_host_t vm)
300 /* will jump to SIMIX_pre_vm_start in src/simix/smx_smurf_private.h */
301 simcall_BODY_vm_start(vm);
305 * \ingroup simix_vm_management
306 * \brief Get the state of the given VM
309 * \return The state of the VM
311 int simcall_vm_get_state(smx_host_t vm)
313 /* will jump to SIMIX_pre_vm_get_state in src/simix/smx_smurf_private.h */
314 return simcall_BODY_vm_get_state(vm);
318 * \ingroup simix_vm_management
319 * \brief Get the name of the physical host on which the given VM runs.
322 * \return The name of the physical host
324 const char *simcall_vm_get_phys_host(smx_host_t vm)
326 /* will jump to SIMIX_pre_vm_migrate in src/simix/smx_smurf_private.h */
327 simcall_BODY_vm_get_phys_host(vm);
331 * \ingroup simix_vm_management
332 * \brief Migrate the given VM to the given physical host
335 * \param host Destination physical host
337 void simcall_vm_migrate(smx_host_t vm, smx_host_t host)
339 /* will jump to SIMIX_pre_vm_migrate in src/simix/smx_smurf_private.h */
340 simcall_BODY_vm_migrate(vm, host);
344 * \ingroup simix_vm_management
345 * \brief Suspend the given VM
349 void simcall_vm_suspend(smx_host_t vm)
351 /* will jump to SIMIX_pre_vm_suspend in src/simix/smx_smurf_private.h */
352 simcall_BODY_vm_suspend(vm);
356 * \ingroup simix_vm_management
357 * \brief Resume the given VM
361 void simcall_vm_resume(smx_host_t vm)
363 /* will jump to SIMIX_pre_vm_resume in src/simix/smx_smurf_private.h */
364 simcall_BODY_vm_resume(vm);
368 * \ingroup simix_vm_management
369 * \brief Save the given VM
373 void simcall_vm_save(smx_host_t vm)
375 /* will jump to SIMIX_pre_vm_save in src/simix/smx_smurf_private.h */
376 simcall_BODY_vm_save(vm);
380 * \ingroup simix_vm_management
381 * \brief Restore the given VM
385 void simcall_vm_restore(smx_host_t vm)
387 /* will jump to SIMIX_pre_vm_restore in src/simix/smx_smurf_private.h */
388 simcall_BODY_vm_restore(vm);
392 * \ingroup simix_vm_management
393 * \brief Shutdown the given VM
397 void simcall_vm_shutdown(smx_host_t vm)
399 /* will jump to SIMIX_pre_vm_shutdown in src/simix/smx_smurf_private.h */
400 simcall_BODY_vm_shutdown(vm);
404 * \ingroup simix_vm_management
405 * \brief Destroy the given VM
409 void simcall_vm_destroy(smx_host_t vm)
411 /* will jump to SIMIX_pre_vm_destroy in src/simix/smx_smurf_private.h */
412 simcall_BODY_vm_destroy(vm);
417 * \ingroup simix_process_management
418 * \brief Creates and runs a new SIMIX process.
420 * The structure and the corresponding thread are created and put in the list of ready processes.
422 * \param process the process created will be stored in this pointer
423 * \param name a name for the process. It is for user-level information and can be NULL.
424 * \param code the main function of the process
425 * \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.
426 * It can be retrieved with the function \ref simcall_process_get_data.
427 * \param hostname name of the host where the new agent is executed.
428 * \param kill_time time when the process is killed
429 * \param argc first argument passed to \a code
430 * \param argv second argument passed to \a code
431 * \param properties the properties of the process
432 * \param auto_restart either it is autorestarting or not.
434 void simcall_process_create(smx_process_t *process, const char *name,
435 xbt_main_func_t code,
437 const char *hostname,
439 int argc, char **argv,
440 xbt_dict_t properties,
443 simcall_BODY_process_create(process, name, code, data, hostname,
444 kill_time, argc, argv, properties,
449 * \ingroup simix_process_management
450 * \brief Kills a SIMIX process.
452 * This function simply kills a process.
454 * \param process poor victim
456 void simcall_process_kill(smx_process_t process)
458 simcall_BODY_process_kill(process);
462 * \ingroup simix_process_management
463 * \brief Kills all SIMIX processes.
465 void simcall_process_killall(int reset_pid)
467 simcall_BODY_process_killall(reset_pid);
471 * \ingroup simix_process_management
472 * \brief Cleans up a SIMIX process.
473 * \param process poor victim (must have already been killed)
475 void simcall_process_cleanup(smx_process_t process)
477 simcall_BODY_process_cleanup(process);
481 * \ingroup simix_process_management
482 * \brief Migrates an agent to another location.
484 * This function changes the value of the host on which \a process is running.
486 * \param process the process to migrate
487 * \param dest name of the new host
489 void simcall_process_change_host(smx_process_t process, smx_host_t dest)
491 simcall_BODY_process_change_host(process, dest);
495 * \ingroup simix_process_management
496 * \brief Suspends a process.
498 * This function suspends the process by suspending the action
499 * it was waiting for completion.
501 * \param process a SIMIX process
503 void simcall_process_suspend(smx_process_t process)
505 xbt_assert(process, "Invalid parameters");
507 simcall_BODY_process_suspend(process);
511 * \ingroup simix_process_management
512 * \brief Resumes a suspended process.
514 * This function resumes a suspended process by resuming the action
515 * it was waiting for completion.
517 * \param process a SIMIX process
519 void simcall_process_resume(smx_process_t process)
521 simcall_BODY_process_resume(process);
525 * \ingroup simix_process_management
526 * \brief Returns the amount of SIMIX processes in the system
528 * Maestro internal process is not counted, only user code processes are
530 int simcall_process_count(void)
532 return simcall_BODY_process_count();
536 * \ingroup simix_process_management
537 * \brief Return the PID of a #smx_process_t.
538 * \param process a SIMIX process
539 * \return the PID of this process
541 int simcall_process_get_PID(smx_process_t process)
543 if (process == SIMIX_process_self()) {
544 /* avoid a simcall if this function is called by the process itself */
545 return SIMIX_process_get_PID(process);
548 return simcall_BODY_process_get_PID(process);
552 * \ingroup simix_process_management
553 * \brief Return the parent PID of a #smx_process_t.
554 * \param process a SIMIX process
555 * \return the PID of this process parenrt
557 int simcall_process_get_PPID(smx_process_t process)
559 if (process == SIMIX_process_self()) {
560 /* avoid a simcall if this function is called by the process itself */
561 return SIMIX_process_get_PPID(process);
564 return simcall_BODY_process_get_PPID(process);
568 * \ingroup simix_process_management
569 * \brief Return the user data of a #smx_process_t.
570 * \param process a SIMIX process
571 * \return the user data of this process
573 void* simcall_process_get_data(smx_process_t process)
575 if (process == SIMIX_process_self()) {
576 /* avoid a simcall if this function is called by the process itself */
577 return SIMIX_process_get_data(process);
580 return simcall_BODY_process_get_data(process);
584 * \ingroup simix_process_management
585 * \brief Set the user data of a #smx_process_t.
587 * This functions sets the user data associated to \a process.
588 * \param process SIMIX process
589 * \param data User data
591 void simcall_process_set_data(smx_process_t process, void *data)
593 if (process == SIMIX_process_self()) {
594 /* avoid a simcall if this function is called by the process itself */
595 SIMIX_process_self_set_data(process, data);
598 simcall_BODY_process_set_data(process, data);
603 * \ingroup simix_process_management
604 * \brief Set the kill time of a process.
605 * \param process a process
606 * \param kill_time a double
608 void simcall_process_set_kill_time(smx_process_t process, double kill_time)
611 if (kill_time > SIMIX_get_clock()) {
612 if (simix_global->kill_process_function) {
613 XBT_DEBUG("Set kill time %f for process %s(%s)",kill_time, process->name,
614 sg_host_name(process->smx_host));
615 SIMIX_timer_set(kill_time, simix_global->kill_process_function, process);
621 * \ingroup simix_process_management
622 * \brief Return the location on which an agent is running.
624 * This functions returns the smx_host_t corresponding to the location on which
625 * \a process is running.
626 * \param process SIMIX process
629 smx_host_t simcall_process_get_host(smx_process_t process)
631 return simcall_BODY_process_get_host(process);
635 * \ingroup simix_process_management
636 * \brief Return the name of an agent.
638 * This functions checks whether \a process is a valid pointer or not and return its name.
639 * \param process SIMIX process
640 * \return The process name
642 const char* simcall_process_get_name(smx_process_t process)
644 if (process == SIMIX_process_self()) {
645 /* avoid a simcall if this function is called by the process itself */
646 return process->name;
648 return simcall_BODY_process_get_name(process);
652 * \ingroup simix_process_management
653 * \brief Returns true if the process is suspended .
655 * This checks whether a process is suspended or not by inspecting the task on which it was waiting for the completion.
656 * \param process SIMIX process
657 * \return 1, if the process is suspended, else 0.
659 int simcall_process_is_suspended(smx_process_t process)
661 return simcall_BODY_process_is_suspended(process);
665 * \ingroup simix_process_management
666 * \brief Return the properties
668 * This functions returns the properties associated with this process
670 xbt_dict_t simcall_process_get_properties(smx_process_t process)
672 return simcall_BODY_process_get_properties(process);
675 * \ingroup simix_process_management
676 * \brief Add an on_exit function
677 * Add an on_exit function which will be executed when the process exits/is killed.
679 XBT_PUBLIC(void) simcall_process_on_exit(smx_process_t process, int_f_pvoid_t fun, void *data)
681 simcall_BODY_process_on_exit(process, fun, data);
684 * \ingroup simix_process_management
685 * \brief Sets the process to be auto-restarted or not by SIMIX when its host comes back up.
686 * Will restart the process when the host comes back up if auto_restart is set to 1.
689 XBT_PUBLIC(void) simcall_process_auto_restart_set(smx_process_t process, int auto_restart)
691 simcall_BODY_process_auto_restart_set(process, auto_restart);
695 * \ingroup simix_process_management
696 * \brief Restarts the process, killing it and starting it again from scratch.
698 XBT_PUBLIC(smx_process_t) simcall_process_restart(smx_process_t process)
700 return simcall_BODY_process_restart(process);
703 * \ingroup simix_process_management
704 * \brief Creates a new sleep SIMIX action.
706 * This function creates a SURF action and allocates the data necessary
707 * to create the SIMIX action. It can raise a host_error exception if the
708 * host crashed. The default SIMIX name of the action is "sleep".
710 * \param duration Time duration of the sleep.
711 * \return A result telling whether the sleep was successful
713 e_smx_state_t simcall_process_sleep(double duration)
715 /* checking for infinite values */
716 xbt_assert(isfinite(duration), "duration is not finite!");
717 return simcall_BODY_process_sleep(duration);
721 * \ingroup simix_rdv_management
722 * \brief Creates a new rendez-vous point
723 * \param name The name of the rendez-vous point
724 * \return The created rendez-vous point
726 smx_rdv_t simcall_rdv_create(const char *name)
728 return simcall_BODY_rdv_create(name);
733 * \ingroup simix_rdv_management
734 * \brief Destroy a rendez-vous point
735 * \param rdv The rendez-vous point to destroy
737 void simcall_rdv_destroy(smx_rdv_t rdv)
739 simcall_BODY_rdv_destroy(rdv);
742 * \ingroup simix_rdv_management
743 * \brief Returns a rendez-vous point knowing its name
745 smx_rdv_t simcall_rdv_get_by_name(const char *name)
747 xbt_assert(name != NULL, "Invalid parameter for simcall_rdv_get_by_name (name is NULL)");
749 /* FIXME: this is a horrible lost of performance, so we hack it out by
750 * skipping the simcall (for now). It works in parallel, it won't work on
751 * distributed but probably we will change MSG for that. */
754 smx_simcall_t simcall = simcall_mine();
755 simcall->call = SIMCALL_RDV_GEY_BY_NAME;
756 simcall->rdv_get_by_name.name = name;
757 SIMIX_simcall_push(simcall->issuer);
758 return simcall->rdv_get_by_name.result;*/
760 return SIMIX_rdv_get_by_name(name);
764 * \ingroup simix_rdv_management
765 * \brief Counts the number of communication actions of a given host pending
766 * on a rendez-vous point.
767 * \param rdv The rendez-vous point
768 * \param host The host to be counted
769 * \return The number of comm actions pending in the rdv
771 int simcall_rdv_comm_count_by_host(smx_rdv_t rdv, smx_host_t host)
773 return simcall_BODY_rdv_comm_count_by_host(rdv, host);
777 * \ingroup simix_rdv_management
778 * \brief returns the communication at the head of the rendez-vous
779 * \param rdv The rendez-vous point
780 * \return The communication or NULL if empty
782 smx_action_t simcall_rdv_get_head(smx_rdv_t rdv)
784 return simcall_BODY_rdv_get_head(rdv);
787 void simcall_rdv_set_receiver(smx_rdv_t rdv, smx_process_t process)
789 simcall_BODY_rdv_set_receiver(rdv, process);
792 smx_process_t simcall_rdv_get_receiver(smx_rdv_t rdv)
794 return simcall_BODY_rdv_get_receiver(rdv);
798 * \ingroup simix_comm_management
800 void simcall_comm_send(smx_rdv_t rdv, double task_size, double rate,
801 void *src_buff, size_t src_buff_size,
802 int (*match_fun)(void *, void *, smx_action_t), void *data,
805 /* checking for infinite values */
806 xbt_assert(isfinite(task_size), "task_size is not finite!");
807 xbt_assert(isfinite(rate), "rate is not finite!");
808 xbt_assert(isfinite(timeout), "timeout is not finite!");
810 xbt_assert(rdv, "No rendez-vous point defined for send");
812 if (MC_is_active()) {
813 /* the model-checker wants two separate simcalls */
814 smx_action_t comm = simcall_comm_isend(rdv, task_size, rate,
815 src_buff, src_buff_size, match_fun, NULL, data, 0);
816 simcall_comm_wait(comm, timeout);
819 simcall_BODY_comm_send(rdv, task_size, rate, src_buff, src_buff_size,
820 match_fun, data, timeout);
825 * \ingroup simix_comm_management
827 smx_action_t simcall_comm_isend(smx_rdv_t rdv, double task_size, double rate,
828 void *src_buff, size_t src_buff_size,
829 int (*match_fun)(void *, void *, smx_action_t),
830 void (*clean_fun)(void *),
834 /* checking for infinite values */
835 xbt_assert(isfinite(task_size), "task_size is not finite!");
836 xbt_assert(isfinite(rate), "rate is not finite!");
838 xbt_assert(rdv, "No rendez-vous point defined for isend");
840 return simcall_BODY_comm_isend(rdv, task_size, rate, src_buff,
841 src_buff_size, match_fun,
842 clean_fun, data, detached);
845 * \ingroup simix_comm_management
847 void simcall_comm_recv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
848 int (*match_fun)(void *, void *, smx_action_t), void *data, double timeout)
850 xbt_assert(isfinite(timeout), "timeout is not finite!");
851 xbt_assert(rdv, "No rendez-vous point defined for recv");
853 if (MC_is_active()) {
854 /* the model-checker wants two separate simcalls */
855 smx_action_t comm = simcall_comm_irecv(rdv, dst_buff, dst_buff_size,
857 simcall_comm_wait(comm, timeout);
860 simcall_BODY_comm_recv(rdv, dst_buff, dst_buff_size,
861 match_fun, data, timeout);
865 * \ingroup simix_comm_management
867 smx_action_t simcall_comm_irecv(smx_rdv_t rdv, void *dst_buff, size_t *dst_buff_size,
868 int (*match_fun)(void *, void *, smx_action_t), void *data)
870 xbt_assert(rdv, "No rendez-vous point defined for irecv");
872 return simcall_BODY_comm_irecv(rdv, dst_buff, dst_buff_size,
878 * \ingroup simix_comm_management
880 smx_action_t simcall_comm_iprobe(smx_rdv_t rdv, int src, int tag,
881 int (*match_fun)(void *, void *, smx_action_t), void *data)
883 xbt_assert(rdv, "No rendez-vous point defined for iprobe");
885 return simcall_BODY_comm_iprobe(rdv, src, tag, match_fun, data);
888 void simcall_comm_destroy(smx_action_t comm)
890 xbt_assert(comm, "Invalid parameter");
892 /* FIXME remove this simcall type: comms are auto-destroyed now */
895 smx_simcall_t simcall = simcall_mine();
897 simcall->call = SIMCALL_COMM_DESTROY;
898 simcall->comm_destroy.comm = comm;
900 SIMIX_simcall_push(simcall->issuer);
905 * \ingroup simix_comm_management
907 void simcall_comm_cancel(smx_action_t comm)
909 simcall_BODY_comm_cancel(comm);
913 * \ingroup simix_comm_management
915 unsigned int simcall_comm_waitany(xbt_dynar_t comms)
917 return simcall_BODY_comm_waitany(comms);
921 * \ingroup simix_comm_management
923 int simcall_comm_testany(xbt_dynar_t comms)
925 if (xbt_dynar_is_empty(comms))
927 return simcall_BODY_comm_testany(comms);
931 * \ingroup simix_comm_management
933 void simcall_comm_wait(smx_action_t comm, double timeout)
935 xbt_assert(isfinite(timeout), "timeout is not finite!");
936 simcall_BODY_comm_wait(comm, timeout);
941 * \brief Set the category of an action.
943 * This functions changes the category only. It calls a surf function.
944 * \param execution The execution action
945 * \param category The tracing category
947 void simcall_set_category(smx_action_t action, const char *category)
949 if (category == NULL) {
952 simcall_BODY_set_category(action, category);
957 * \ingroup simix_comm_management
960 int simcall_comm_test(smx_action_t comm)
962 return simcall_BODY_comm_test(comm);
966 * \ingroup simix_comm_management
969 double simcall_comm_get_remains(smx_action_t comm)
971 return simcall_BODY_comm_get_remains(comm);
975 * \ingroup simix_comm_management
978 e_smx_state_t simcall_comm_get_state(smx_action_t comm)
980 return simcall_BODY_comm_get_state(comm);
984 * \ingroup simix_comm_management
987 void *simcall_comm_get_src_data(smx_action_t comm)
989 return simcall_BODY_comm_get_src_data(comm);
993 * \ingroup simix_comm_management
996 void *simcall_comm_get_dst_data(smx_action_t comm)
998 return simcall_BODY_comm_get_dst_data(comm);
1002 * \ingroup simix_comm_management
1005 smx_process_t simcall_comm_get_src_proc(smx_action_t comm)
1007 return simcall_BODY_comm_get_src_proc(comm);
1011 * \ingroup simix_comm_management
1014 smx_process_t simcall_comm_get_dst_proc(smx_action_t comm)
1016 return simcall_BODY_comm_get_dst_proc(comm);
1019 #ifdef HAVE_LATENCY_BOUND_TRACKING
1020 int simcall_comm_is_latency_bounded(smx_action_t comm)
1022 return simcall_BODY_comm_is_latency_bounded(comm);
1027 * \ingroup simix_synchro_management
1030 smx_mutex_t simcall_mutex_init(void)
1033 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
1036 return simcall_BODY_mutex_init();
1040 * \ingroup simix_synchro_management
1043 void simcall_mutex_destroy(smx_mutex_t mutex)
1045 simcall_BODY_mutex_destroy(mutex);
1049 * \ingroup simix_synchro_management
1052 void simcall_mutex_lock(smx_mutex_t mutex)
1054 simcall_BODY_mutex_lock(mutex);
1058 * \ingroup simix_synchro_management
1061 int simcall_mutex_trylock(smx_mutex_t mutex)
1063 return simcall_BODY_mutex_trylock(mutex);
1067 * \ingroup simix_synchro_management
1070 void simcall_mutex_unlock(smx_mutex_t mutex)
1072 simcall_BODY_mutex_unlock(mutex);
1076 * \ingroup simix_synchro_management
1079 smx_cond_t simcall_cond_init(void)
1081 return simcall_BODY_cond_init();
1085 * \ingroup simix_synchro_management
1088 void simcall_cond_destroy(smx_cond_t cond)
1090 simcall_BODY_cond_destroy(cond);
1094 * \ingroup simix_synchro_management
1097 void simcall_cond_signal(smx_cond_t cond)
1099 simcall_BODY_cond_signal(cond);
1103 * \ingroup simix_synchro_management
1106 void simcall_cond_wait(smx_cond_t cond, smx_mutex_t mutex)
1108 simcall_BODY_cond_wait(cond, mutex);
1112 * \ingroup simix_synchro_management
1115 void simcall_cond_wait_timeout(smx_cond_t cond,
1119 xbt_assert(isfinite(timeout), "timeout is not finite!");
1120 simcall_BODY_cond_wait_timeout(cond, mutex, timeout);
1124 * \ingroup simix_synchro_management
1127 void simcall_cond_broadcast(smx_cond_t cond)
1129 simcall_BODY_cond_broadcast(cond);
1133 * \ingroup simix_synchro_management
1136 smx_sem_t simcall_sem_init(int capacity)
1138 return simcall_BODY_sem_init(capacity);
1142 * \ingroup simix_synchro_management
1145 void simcall_sem_destroy(smx_sem_t sem)
1147 simcall_sem_destroy(sem);
1151 * \ingroup simix_synchro_management
1154 void simcall_sem_release(smx_sem_t sem)
1156 simcall_BODY_sem_release(sem);
1160 * \ingroup simix_synchro_management
1163 int simcall_sem_would_block(smx_sem_t sem)
1165 return simcall_BODY_sem_would_block(sem);
1169 * \ingroup simix_synchro_management
1172 void simcall_sem_acquire(smx_sem_t sem)
1174 simcall_BODY_sem_acquire(sem);
1178 * \ingroup simix_synchro_management
1181 void simcall_sem_acquire_timeout(smx_sem_t sem, double timeout)
1183 xbt_assert(isfinite(timeout), "timeout is not finite!");
1184 simcall_BODY_sem_acquire_timeout(sem, timeout);
1188 * \ingroup simix_synchro_management
1191 int simcall_sem_get_capacity(smx_sem_t sem)
1193 return simcall_BODY_sem_get_capacity(sem);
1197 * \ingroup simix_file_management
1200 double simcall_file_read(void* ptr, size_t size, size_t nmemb, smx_file_t stream)
1202 return simcall_BODY_file_read(ptr, size, nmemb, stream);
1206 * \ingroup simix_file_management
1209 size_t simcall_file_write(const void* ptr, size_t size, size_t nmemb, smx_file_t stream)
1211 return simcall_BODY_file_write(ptr, size, nmemb, stream);
1215 * \ingroup simix_file_management
1218 smx_file_t simcall_file_open(const char* mount, const char* path, const char* mode)
1220 return simcall_BODY_file_open(mount, path, mode);
1224 * \ingroup simix_file_management
1227 int simcall_file_close(smx_file_t fp)
1229 return simcall_BODY_file_close(fp);
1233 * \ingroup simix_file_management
1236 int simcall_file_stat(smx_file_t fd, s_file_stat_t *buf)
1238 return simcall_BODY_file_stat(fd, buf);
1242 * \ingroup simix_file_management
1245 int simcall_file_unlink(smx_file_t fd)
1247 return simcall_BODY_file_unlink(fd);
1251 * \ingroup simix_file_management
1254 xbt_dict_t simcall_file_ls(const char* mount, const char* path)
1256 return simcall_BODY_file_ls(mount, path);
1261 void *simcall_mc_snapshot(void)
1263 return simcall_BODY_mc_snapshot();
1266 int simcall_mc_compare_snapshots(void *s1, void *s2){
1267 return simcall_BODY_mc_compare_snapshots(s1, s2);
1270 #endif /* HAVE_MC */
1272 /* ****************************************************************************************** */
1273 /* TUTORIAL: New API */
1274 /* All functions for simcall */
1275 /* ****************************************************************************************** */
1276 int simcall_new_api_fct(const char* param1, double param2){
1277 smx_simcall_t simcall = SIMIX_simcall_mine();
1278 simcall->call = SIMCALL_NEW_API_INIT;
1279 simcall->new_api.param1 = param1;
1280 simcall->new_api.param2 = param2;
1282 SIMIX_simcall_push(simcall->issuer);
1283 return simcall->new_api.result;
1286 /* ************************************************************************** */
1288 /** @brief returns a printable string representing a simcall */
1289 const char *SIMIX_simcall_name(e_smx_simcall_t kind) {
1290 return simcall_names[kind];