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 static const char* simcall_names[] = {
16 #undef SIMCALL_ENUM_ELEMENT
17 #define SIMCALL_ENUM_ELEMENT(x) #x /* generate strings from the enumeration values */
19 #undef SIMCALL_ENUM_ELEMENT
23 * \ingroup simix_host_management
24 * \brief Returns a host given its name.
26 * \param name The name of the host to get
27 * \return The corresponding host
29 smx_host_t simcall_host_get_by_name(const char *name)
31 smx_simcall_t simcall = SIMIX_simcall_mine();
33 simcall->call = SIMCALL_HOST_GET_BY_NAME;
34 simcall->host_get_by_name.name = name;
35 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
36 simcall->host_get_by_name.result = NULL;
37 SIMIX_simcall_push(simcall->issuer);
38 return simcall->host_get_by_name.result;
42 * \ingroup simix_host_management
43 * \brief Returns the name of a host.
45 * \param host A SIMIX host
46 * \return The name of this host
48 const char* simcall_host_get_name(smx_host_t host)
50 smx_simcall_t simcall = SIMIX_simcall_mine();
52 simcall->call = SIMCALL_HOST_GET_NAME;
53 simcall->host_get_name.host = host;
54 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
55 simcall->host_get_name.result = NULL;
56 SIMIX_simcall_push(simcall->issuer);
57 return simcall->host_get_name.result;
61 * \ingroup simix_host_management
62 * \brief Returns a dict of the properties assigned to a host.
65 * \return The properties of this host
67 xbt_dict_t simcall_host_get_properties(smx_host_t host)
69 smx_simcall_t simcall = SIMIX_simcall_mine();
71 simcall->call = SIMCALL_HOST_GET_PROPERTIES;
72 simcall->host_get_properties.host = host;
73 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
74 simcall->host_get_properties.result = NULL;
75 SIMIX_simcall_push(simcall->issuer);
76 return simcall->host_get_properties.result;
80 * \ingroup simix_host_management
81 * \brief Returns a dict of the properties assigned to a router or AS.
83 * \param name The name of the router or AS
84 * \return The properties
86 xbt_dict_t simcall_asr_get_properties(const char *name)
88 smx_simcall_t simcall = SIMIX_simcall_mine();
90 simcall->call = SIMCALL_ASR_GET_PROPERTIES;
91 simcall->asr_get_properties.name = name;
92 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
93 simcall->asr_get_properties.result = NULL;
94 SIMIX_simcall_push(simcall->issuer);
95 return simcall->asr_get_properties.result;
100 * \ingroup simix_host_management
101 * \brief Returns the speed of the processor.
103 * The speed returned does not take into account the current load on the machine.
104 * \param host A SIMIX host
105 * \return The speed of this host (in Mflop/s)
107 double simcall_host_get_speed(smx_host_t host)
109 smx_simcall_t simcall = SIMIX_simcall_mine();
111 simcall->call = SIMCALL_HOST_GET_SPEED;
112 simcall->host_get_speed.host = host;
113 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
114 simcall->host_get_speed.result = 0.0;
115 SIMIX_simcall_push(simcall->issuer);
116 return simcall->host_get_speed.result;
120 * \ingroup simix_host_management
121 * \brief Returns the available speed of the processor.
123 * \return Speed currently available (in Mflop/s)
125 double simcall_host_get_available_speed(smx_host_t host)
127 smx_simcall_t simcall = SIMIX_simcall_mine();
129 simcall->call = SIMCALL_HOST_GET_AVAILABLE_SPEED;
130 simcall->host_get_available_speed.host = host;
131 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
132 simcall->host_get_available_speed.result = 0.0;
133 SIMIX_simcall_push(simcall->issuer);
134 return simcall->host_get_available_speed.result;
138 * \ingroup simix_host_management
139 * \brief Returns the state of a host.
141 * Two states are possible: 1 if the host is active or 0 if it has crashed.
142 * \param host A SIMIX host
143 * \return 1 if the host is available, 0 otherwise
145 int simcall_host_get_state(smx_host_t host)
147 smx_simcall_t simcall = SIMIX_simcall_mine();
149 simcall->call = SIMCALL_HOST_GET_STATE;
150 simcall->host_get_state.host = host;
151 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
152 simcall->host_get_state.result = -1;
153 SIMIX_simcall_push(simcall->issuer);
154 return simcall->host_get_state.result;
158 * \ingroup simix_host_management
159 * \brief Returns the user data associated to a host.
161 * \param host SIMIX host
162 * \return the user data of this host
164 void* simcall_host_get_data(smx_host_t host)
166 smx_simcall_t simcall = SIMIX_simcall_mine();
168 simcall->call = SIMCALL_HOST_GET_DATA;
169 simcall->host_get_data.host = host;
170 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
171 simcall->host_get_data.result = NULL;
172 SIMIX_simcall_push(simcall->issuer);
173 return simcall->host_get_data.result;
177 * \ingroup simix_host_management
178 * \brief Sets the user data associated to a host.
180 * The host must not have previous user data associated to it.
181 * \param host A SIMIX host
182 * \param data The user data to set
184 void simcall_host_set_data(smx_host_t host, void *data)
186 smx_simcall_t simcall = SIMIX_simcall_mine();
188 simcall->call = SIMCALL_HOST_SET_DATA;
189 simcall->host_set_data.host = host;
190 simcall->host_set_data.data = data;
191 SIMIX_simcall_push(simcall->issuer);
195 * \ingroup simix_host_management
196 * \brief Creates an action that executes some computation of an host.
198 * This function creates a SURF action and allocates the data necessary
199 * to create the SIMIX action. It can raise a host_error exception if the host crashed.
201 * \param name Name of the execution action to create
202 * \param host SIMIX host where the action will be executed
203 * \param computation_amount amount Computation amount (in bytes)
204 * \param priority computation priority
205 * \return A new SIMIX execution action
207 smx_action_t simcall_host_execute(const char *name, smx_host_t host,
208 double computation_amount,
211 /* checking for infinite values */
212 xbt_assert(isfinite(computation_amount), "computation_amount is not finite!");
213 xbt_assert(isfinite(priority), "priority is not finite!");
215 smx_simcall_t simcall = SIMIX_simcall_mine();
217 simcall->call = SIMCALL_HOST_EXECUTE;
218 simcall->host_execute.name = name;
219 simcall->host_execute.host = host;
220 simcall->host_execute.computation_amount = computation_amount;
221 simcall->host_execute.priority = priority;
222 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
223 simcall->host_execute.result = NULL;
224 SIMIX_simcall_push(simcall->issuer);
225 return simcall->host_execute.result;
229 * \ingroup simix_host_management
230 * \brief Creates an action that may involve parallel computation on
231 * several hosts and communication between them.
233 * \param name Name of the execution action to create
234 * \param host_nb Number of hosts where the action will be executed
235 * \param host_list Array (of size host_nb) of hosts where the action will be executed
236 * \param computation_amount Array (of size host_nb) of computation amount of hosts (in bytes)
237 * \param communication_amount Array (of size host_nb * host_nb) representing the communication
238 * amount between each pair of hosts
239 * \param amount the SURF action amount
240 * \param rate the SURF action rate
241 * \return A new SIMIX execution action
243 smx_action_t simcall_host_parallel_execute(const char *name,
245 smx_host_t *host_list,
246 double *computation_amount,
247 double *communication_amount,
252 /* checking for infinite values */
253 for (i = 0 ; i < host_nb ; ++i) {
254 xbt_assert(isfinite(computation_amount[i]), "computation_amount[%d] is not finite!", i);
255 for (j = 0 ; j < host_nb ; ++j) {
256 xbt_assert(isfinite(communication_amount[i + host_nb * j]),
257 "communication_amount[%d+%d*%d] is not finite!", i, host_nb, j);
261 xbt_assert(isfinite(amount), "amount is not finite!");
262 xbt_assert(isfinite(rate), "rate is not finite!");
264 smx_simcall_t simcall = SIMIX_simcall_mine();
266 simcall->call = SIMCALL_HOST_PARALLEL_EXECUTE;
267 simcall->host_parallel_execute.name = name;
268 simcall->host_parallel_execute.host_nb = host_nb;
269 simcall->host_parallel_execute.host_list = host_list;
270 simcall->host_parallel_execute.computation_amount = computation_amount;
271 simcall->host_parallel_execute.communication_amount = communication_amount;
272 simcall->host_parallel_execute.amount = amount;
273 simcall->host_parallel_execute.rate = rate;
274 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
275 simcall->host_parallel_execute.result = NULL;
276 SIMIX_simcall_push(simcall->issuer);
277 return simcall->host_parallel_execute.result;
281 * \ingroup simix_host_management
282 * \brief Destroys an execution action.
284 * Destroys an action, freing its memory. This function cannot be called if there are a conditional waiting for it.
285 * \param execution The execution action to destroy
287 void simcall_host_execution_destroy(smx_action_t execution)
289 smx_simcall_t simcall = SIMIX_simcall_mine();
291 simcall->call = SIMCALL_HOST_EXECUTION_DESTROY;
292 simcall->host_execution_destroy.execution = execution;
293 SIMIX_simcall_push(simcall->issuer);
297 * \ingroup simix_host_management
298 * \brief Cancels an execution action.
300 * This functions stops the execution. It calls a surf function.
301 * \param execution The execution action to cancel
303 void simcall_host_execution_cancel(smx_action_t execution)
305 smx_simcall_t simcall = SIMIX_simcall_mine();
307 simcall->call = SIMCALL_HOST_EXECUTION_CANCEL;
308 simcall->host_execution_cancel.execution = execution;
309 SIMIX_simcall_push(simcall->issuer);
313 * \ingroup simix_host_management
314 * \brief Returns how much of an execution action remains to be done.
316 * \param execution The execution action
317 * \return The remaining amount
319 double simcall_host_execution_get_remains(smx_action_t execution)
321 smx_simcall_t simcall = SIMIX_simcall_mine();
323 simcall->call = SIMCALL_HOST_EXECUTION_GET_REMAINS;
324 simcall->host_execution_get_remains.execution = execution;
325 if(MC_is_active()) /* Initializeialize result to a default value for snapshot comparison done during simcall */
326 simcall->host_execution_get_remains.result = 0.0;
327 SIMIX_simcall_push(simcall->issuer);
328 return simcall->host_execution_get_remains.result;
332 * \ingroup simix_host_management
333 * \brief Returns the state of an execution action.
335 * \param execution The execution action
338 e_smx_state_t simcall_host_execution_get_state(smx_action_t execution)
340 smx_simcall_t simcall = SIMIX_simcall_mine();
342 simcall->call = SIMCALL_HOST_EXECUTION_GET_STATE;
343 simcall->host_execution_get_state.execution = execution;
344 simcall->host_execution_get_state.result = -1;
345 SIMIX_simcall_push(simcall->issuer);
346 return simcall->host_execution_get_state.result;
350 * \ingroup simix_host_management
351 * \brief Changes the priority of an execution action.
353 * This functions changes the priority only. It calls a surf function.
354 * \param execution The execution action
355 * \param priority The new priority
357 void simcall_host_execution_set_priority(smx_action_t execution, double priority)
359 /* checking for infinite values */
360 xbt_assert(isfinite(priority), "priority is not finite!");
362 smx_simcall_t simcall = SIMIX_simcall_mine();
364 simcall->call = SIMCALL_HOST_EXECUTION_SET_PRIORITY;
365 simcall->host_execution_set_priority.execution = execution;
366 simcall->host_execution_set_priority.priority = priority;
367 SIMIX_simcall_push(simcall->issuer);
371 * \ingroup simix_host_management
372 * \brief Waits for the completion of an execution action and destroy it.
374 * \param execution The execution action
376 e_smx_state_t simcall_host_execution_wait(smx_action_t execution)
378 smx_simcall_t simcall = SIMIX_simcall_mine();
380 simcall->call = SIMCALL_HOST_EXECUTION_WAIT;
381 simcall->host_execution_wait.execution = execution;
382 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
383 simcall->host_execution_wait.result = -1;
384 SIMIX_simcall_push(simcall->issuer);
385 return simcall->host_execution_wait.result;
389 * \ingroup simix_process_management
390 * \brief Creates and runs a new SIMIX process.
392 * The structure and the corresponding thread are created and put in the list of ready processes.
394 * \param process the process created will be stored in this pointer
395 * \param name a name for the process. It is for user-level information and can be NULL.
396 * \param code the main function of the process
397 * \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.
398 * It can be retrieved with the function \ref simcall_process_get_data.
399 * \param hostname name of the host where the new agent is executed.
400 * \param kill_time time when the process is killed
401 * \param argc first argument passed to \a code
402 * \param argv second argument passed to \a code
403 * \param properties the properties of the process
404 * \param auto_restart either it is autorestarting or not.
406 void simcall_process_create(smx_process_t *process, const char *name,
407 xbt_main_func_t code,
409 const char *hostname,
411 int argc, char **argv,
412 xbt_dict_t properties,
415 smx_simcall_t simcall = SIMIX_simcall_mine();
417 simcall->call = SIMCALL_PROCESS_CREATE;
418 simcall->process_create.process = process;
419 simcall->process_create.name = name;
420 simcall->process_create.code = code;
421 simcall->process_create.data = data;
422 simcall->process_create.hostname = hostname;
423 simcall->process_create.kill_time = kill_time;
424 simcall->process_create.argc = argc;
425 simcall->process_create.argv = argv;
426 simcall->process_create.properties = properties;
427 simcall->process_create.auto_restart = auto_restart;
428 SIMIX_simcall_push(simcall->issuer);
432 * \ingroup simix_process_management
433 * \brief Kills a SIMIX process.
435 * This function simply kills a process.
437 * \param process poor victim
439 void simcall_process_kill(smx_process_t process)
441 smx_simcall_t simcall = SIMIX_simcall_mine();
443 simcall->call = SIMCALL_PROCESS_KILL;
444 simcall->process_kill.process = process;
445 SIMIX_simcall_push(simcall->issuer);
449 * \ingroup simix_process_management
450 * \brief Kills all SIMIX processes.
452 void simcall_process_killall(void)
454 smx_simcall_t simcall = SIMIX_simcall_mine();
456 simcall->call = SIMCALL_PROCESS_KILLALL;
457 SIMIX_simcall_push(simcall->issuer);
461 * \ingroup simix_process_management
462 * \brief Cleans up a SIMIX process.
463 * \param process poor victim (must have already been killed)
465 void simcall_process_cleanup(smx_process_t process)
467 smx_simcall_t simcall = SIMIX_simcall_mine();
469 simcall->call = SIMCALL_PROCESS_CLEANUP;
470 simcall->process_cleanup.process = process;
471 SIMIX_simcall_push(simcall->issuer);
475 * \ingroup simix_process_management
476 * \brief Migrates an agent to another location.
478 * This function changes the value of the host on which \a process is running.
480 * \param process the process to migrate
481 * \param dest name of the new host
483 void simcall_process_change_host(smx_process_t process, smx_host_t dest)
485 smx_simcall_t simcall = SIMIX_simcall_mine();
487 simcall->call = SIMCALL_PROCESS_CHANGE_HOST;
488 simcall->process_change_host.process = process;
489 simcall->process_change_host.dest = dest;
490 SIMIX_simcall_push(simcall->issuer);
494 * \ingroup simix_process_management
495 * \brief Suspends a process.
497 * This function suspends the process by suspending the action
498 * it was waiting for completion.
500 * \param process a SIMIX process
502 void simcall_process_suspend(smx_process_t process)
504 xbt_assert(process, "Invalid parameters");
506 smx_simcall_t simcall = SIMIX_simcall_mine();
508 simcall->call = SIMCALL_PROCESS_SUSPEND;
509 simcall->process_suspend.process = process;
510 SIMIX_simcall_push(simcall->issuer);
514 * \ingroup simix_process_management
515 * \brief Resumes a suspended process.
517 * This function resumes a suspended process by resuming the action
518 * it was waiting for completion.
520 * \param process a SIMIX process
522 void simcall_process_resume(smx_process_t process)
524 smx_simcall_t simcall = SIMIX_simcall_mine();
526 simcall->call = SIMCALL_PROCESS_RESUME;
527 simcall->process_resume.process = process;
528 SIMIX_simcall_push(simcall->issuer);
532 * \ingroup simix_process_management
533 * \brief Returns the amount of SIMIX processes in the system
535 * Maestro internal process is not counted, only user code processes are
537 int simcall_process_count(void)
539 smx_simcall_t simcall = SIMIX_simcall_mine();
541 simcall->call = SIMCALL_PROCESS_COUNT;
542 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
543 simcall->process_count.result = -1;
544 SIMIX_simcall_push(simcall->issuer);
545 return simcall->process_count.result;
549 * \ingroup simix_process_management
550 * \brief Return the user data of a #smx_process_t.
551 * \param process a SIMIX process
552 * \return the user data of this process
554 void* simcall_process_get_data(smx_process_t process)
556 if (process == SIMIX_process_self()) {
557 /* avoid a simcall if this function is called by the process itself */
558 return SIMIX_process_get_data(process);
561 smx_simcall_t simcall = SIMIX_simcall_mine();
563 simcall->call = SIMCALL_PROCESS_GET_DATA;
564 simcall->process_get_data.process = process;
565 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
566 simcall->process_get_data.result = NULL;
567 SIMIX_simcall_push(simcall->issuer);
568 return simcall->process_get_data.result;
572 * \ingroup simix_process_management
573 * \brief Set the user data of a #smx_process_t.
575 * This functions sets the user data associated to \a process.
576 * \param process SIMIX process
577 * \param data User data
579 void simcall_process_set_data(smx_process_t process, void *data)
581 if (process == SIMIX_process_self()) {
582 /* avoid a simcall if this function is called by the process itself */
583 SIMIX_process_self_set_data(process, data);
587 smx_simcall_t simcall = SIMIX_simcall_mine();
589 simcall->call = SIMCALL_PROCESS_SET_DATA;
590 simcall->process_set_data.process = process;
591 simcall->process_set_data.data = data;
592 SIMIX_simcall_push(simcall->issuer);
597 * \ingroup simix_process_management
598 * \brief Set the kill time of a process.
599 * \param process a process
600 * \param kill_time a double
602 void simcall_process_set_kill_time(smx_process_t process, double kill_time)
605 if (kill_time > SIMIX_get_clock()) {
606 if (simix_global->kill_process_function) {
607 XBT_DEBUG("Set kill time %f for process %s(%s)",kill_time, process->name,
608 process->smx_host->name);
609 SIMIX_timer_set(kill_time, simix_global->kill_process_function, process);
615 * \ingroup simix_process_management
616 * \brief Return the location on which an agent is running.
618 * This functions returns the smx_host_t corresponding to the location on which
619 * \a process is running.
620 * \param process SIMIX process
623 smx_host_t simcall_process_get_host(smx_process_t process)
625 smx_simcall_t simcall = SIMIX_simcall_mine();
627 simcall->call = SIMCALL_PROCESS_GET_HOST;
628 simcall->process_get_host.process = process;
629 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
630 simcall->process_get_host.result = NULL;
631 SIMIX_simcall_push(simcall->issuer);
632 return simcall->process_get_host.result;
636 * \ingroup simix_process_management
637 * \brief Return the name of an agent.
639 * This functions checks whether \a process is a valid pointer or not and return its name.
640 * \param process SIMIX process
641 * \return The process name
643 const char* simcall_process_get_name(smx_process_t process)
645 if (process == SIMIX_process_self()) {
646 /* avoid a simcall if this function is called by the process itself */
647 return process->name;
650 smx_simcall_t simcall = SIMIX_simcall_mine();
652 simcall->call = SIMCALL_PROCESS_GET_NAME;
653 simcall->process_get_name.process = process;
654 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
655 simcall->process_get_name.result = NULL;
656 SIMIX_simcall_push(simcall->issuer);
657 return simcall->process_get_name.result;
661 * \ingroup simix_process_management
662 * \brief Returns true if the process is suspended .
664 * This checks whether a process is suspended or not by inspecting the task on which it was waiting for the completion.
665 * \param process SIMIX process
666 * \return 1, if the process is suspended, else 0.
668 int simcall_process_is_suspended(smx_process_t process)
670 smx_simcall_t simcall = SIMIX_simcall_mine();
672 simcall->call = SIMCALL_PROCESS_IS_SUSPENDED;
673 simcall->process_is_suspended.process = process;
674 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
675 simcall->process_is_suspended.result = -1;
676 SIMIX_simcall_push(simcall->issuer);
677 return simcall->process_is_suspended.result;
681 * \ingroup simix_process_management
682 * \brief Return the properties
684 * This functions returns the properties associated with this process
686 xbt_dict_t simcall_process_get_properties(smx_process_t process)
688 smx_simcall_t simcall = SIMIX_simcall_mine();
690 simcall->call = SIMCALL_PROCESS_GET_PROPERTIES;
691 simcall->process_get_properties.process = process;
692 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
693 simcall->process_get_properties.result = NULL;
694 SIMIX_simcall_push(simcall->issuer);
695 return simcall->process_get_properties.result;
698 * \ingroup simix_process_management
699 * \brief Add an on_exit function
700 * Add an on_exit function which will be executed when the process exits/is killed.
702 XBT_PUBLIC(void) simcall_process_on_exit(smx_process_t process, int_f_pvoid_t fun, void *data)
704 smx_simcall_t simcall = SIMIX_simcall_mine();
706 simcall->call = SIMCALL_PROCESS_ON_EXIT;
707 simcall->process_on_exit.process = process;
708 simcall->process_on_exit.fun = fun;
709 simcall->process_on_exit.data = data;
711 SIMIX_simcall_push(simcall->issuer);
714 * \ingroup simix_process_management
715 * \brief Sets the process to be auto-restarted or not by SIMIX when its host comes back up.
716 * Will restart the process when the host comes back up if auto_restart is set to 1.
719 XBT_PUBLIC(void) simcall_process_auto_restart_set(smx_process_t process, int auto_restart)
721 smx_simcall_t simcall = SIMIX_simcall_mine();
723 simcall->call = SIMCALL_PROCESS_AUTO_RESTART_SET;
724 simcall->process_auto_restart.process = process;
725 simcall->process_auto_restart.auto_restart = auto_restart;
727 SIMIX_simcall_push(simcall->issuer);
730 * \ingroup simix_process_management
731 * \brief Restarts the process, killing it and starting it again from scratch.
733 XBT_PUBLIC(smx_process_t) simcall_process_restart(smx_process_t process)
735 smx_simcall_t simcall = SIMIX_simcall_mine();
737 simcall->call = SIMCALL_PROCESS_RESTART;
738 simcall->process_restart.process = process;
739 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
740 simcall->process_restart.result = NULL;
742 SIMIX_simcall_push(simcall->issuer);
744 return simcall->process_restart.result;
747 * \ingroup simix_process_management
748 * \brief Creates a new sleep SIMIX action.
750 * This function creates a SURF action and allocates the data necessary
751 * to create the SIMIX action. It can raise a host_error exception if the
752 * host crashed. The default SIMIX name of the action is "sleep".
754 * \param duration Time duration of the sleep.
755 * \return A result telling whether the sleep was successful
757 e_smx_state_t simcall_process_sleep(double duration)
759 /* checking for infinite values */
760 xbt_assert(isfinite(duration), "duration is not finite!");
762 smx_simcall_t simcall = SIMIX_simcall_mine();
764 simcall->call = SIMCALL_PROCESS_SLEEP;
765 simcall->process_sleep.duration = duration;
766 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
767 simcall->process_sleep.result = -1;
768 SIMIX_simcall_push(simcall->issuer);
769 return simcall->process_sleep.result;
773 * \ingroup simix_rdv_management
774 * \brief Creates a new rendez-vous point
775 * \param name The name of the rendez-vous point
776 * \return The created rendez-vous point
778 smx_rdv_t simcall_rdv_create(const char *name)
780 smx_simcall_t simcall = SIMIX_simcall_mine();
782 simcall->call = SIMCALL_RDV_CREATE;
783 simcall->rdv_create.name = name;
784 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
785 simcall->rdv_create.result = NULL;
787 SIMIX_simcall_push(simcall->issuer);
788 return simcall->rdv_create.result;
793 * \ingroup simix_rdv_management
794 * \brief Destroy a rendez-vous point
795 * \param rdv The rendez-vous point to destroy
797 void simcall_rdv_destroy(smx_rdv_t rdv)
799 smx_simcall_t simcall = SIMIX_simcall_mine();
801 simcall->call = SIMCALL_RDV_DESTROY;
802 simcall->rdv_destroy.rdv = rdv;
804 SIMIX_simcall_push(simcall->issuer);
807 * \ingroup simix_rdv_management
808 * \brief Returns a rendez-vous point knowing its name
810 smx_rdv_t simcall_rdv_get_by_name(const char *name)
812 xbt_assert(name != NULL, "Invalid parameter for simcall_rdv_get_by_name (name is NULL)");
814 /* FIXME: this is a horrible lost of performance, so we hack it out by
815 * skipping the simcall (for now). It works in parallel, it won't work on
816 * distributed but probably we will change MSG for that. */
819 smx_simcall_t simcall = simcall_mine();
820 simcall->call = SIMCALL_RDV_GEY_BY_NAME;
821 simcall->rdv_get_by_name.name = name;
822 SIMIX_simcall_push(simcall->issuer);
823 return simcall->rdv_get_by_name.result;*/
825 return SIMIX_rdv_get_by_name(name);
829 * \ingroup simix_rdv_management
830 * \brief Counts the number of communication actions of a given host pending
831 * on a rendez-vous point.
832 * \param rdv The rendez-vous point
833 * \param host The host to be counted
834 * \return The number of comm actions pending in the rdv
836 int simcall_rdv_comm_count_by_host(smx_rdv_t rdv, smx_host_t host)
838 smx_simcall_t simcall = SIMIX_simcall_mine();
840 simcall->call = SIMCALL_RDV_COMM_COUNT_BY_HOST;
841 simcall->rdv_comm_count_by_host.rdv = rdv;
842 simcall->rdv_comm_count_by_host.host = host;
843 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
844 simcall->rdv_comm_count_by_host.result = -1;
846 SIMIX_simcall_push(simcall->issuer);
847 return simcall->rdv_comm_count_by_host.result;
851 * \ingroup simix_rdv_management
852 * \brief returns the communication at the head of the rendez-vous
853 * \param rdv The rendez-vous point
854 * \return The communication or NULL if empty
856 smx_action_t simcall_rdv_get_head(smx_rdv_t rdv)
858 smx_simcall_t simcall = SIMIX_simcall_mine();
860 simcall->call = SIMCALL_RDV_GET_HEAD;
861 simcall->rdv_get_head.rdv = rdv;
862 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
863 simcall->rdv_get_head.result = NULL;
865 SIMIX_simcall_push(simcall->issuer);
866 return simcall->rdv_get_head.result;
869 void simcall_rdv_set_receiver(smx_rdv_t rdv , smx_process_t process)
871 smx_simcall_t simcall = SIMIX_simcall_mine();
873 simcall->call = SIMCALL_RDV_SET_RECV;
874 simcall->rdv_set_rcv_proc.rdv = rdv;
875 simcall->rdv_set_rcv_proc.receiver = process;
877 SIMIX_simcall_push(simcall->issuer);
880 smx_process_t simcall_rdv_get_receiver(smx_rdv_t rdv)
882 smx_simcall_t simcall = SIMIX_simcall_mine();
884 simcall->call = SIMCALL_RDV_GET_RECV;
885 simcall->rdv_get_rcv_proc.rdv = rdv;
886 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
887 simcall->rdv_get_rcv_proc.result = NULL;
889 SIMIX_simcall_push(simcall->issuer);
890 return simcall->rdv_get_rcv_proc.result;
894 * \ingroup simix_comm_management
896 void simcall_comm_send(smx_rdv_t rdv, double task_size, double rate,
897 void *src_buff, size_t src_buff_size,
898 int (*match_fun)(void *, void *, smx_action_t), void *data,
901 /* checking for infinite values */
902 xbt_assert(isfinite(task_size), "task_size is not finite!");
903 xbt_assert(isfinite(rate), "rate is not finite!");
904 xbt_assert(isfinite(timeout), "timeout is not finite!");
906 xbt_assert(rdv, "No rendez-vous point defined for send");
908 if (MC_is_active()) {
909 /* the model-checker wants two separate simcalls */
910 smx_action_t comm = simcall_comm_isend(rdv, task_size, rate,
911 src_buff, src_buff_size, match_fun, NULL, data, 0);
912 simcall_comm_wait(comm, timeout);
915 smx_simcall_t simcall = SIMIX_simcall_mine();
917 simcall->call = SIMCALL_COMM_SEND;
918 simcall->comm_send.rdv = rdv;
919 simcall->comm_send.task_size = task_size;
920 simcall->comm_send.rate = rate;
921 simcall->comm_send.src_buff = src_buff;
922 simcall->comm_send.src_buff_size = src_buff_size;
923 simcall->comm_send.match_fun = match_fun;
924 simcall->comm_send.data = data;
925 simcall->comm_send.timeout = timeout;
927 SIMIX_simcall_push(simcall->issuer);
931 * \ingroup simix_comm_management
933 smx_action_t simcall_comm_isend(smx_rdv_t rdv, double task_size, double rate,
934 void *src_buff, size_t src_buff_size,
935 int (*match_fun)(void *, void *, smx_action_t),
936 void (*clean_fun)(void *),
940 /* checking for infinite values */
941 xbt_assert(isfinite(task_size), "task_size is not finite!");
942 xbt_assert(isfinite(rate), "rate is not finite!");
944 xbt_assert(rdv, "No rendez-vous point defined for isend");
946 smx_simcall_t simcall = SIMIX_simcall_mine();
948 simcall->call = SIMCALL_COMM_ISEND;
949 simcall->comm_isend.rdv = rdv;
950 simcall->comm_isend.task_size = task_size;
951 simcall->comm_isend.rate = rate;
952 simcall->comm_isend.src_buff = src_buff;
953 simcall->comm_isend.src_buff_size = src_buff_size;
954 simcall->comm_isend.match_fun = match_fun;
955 simcall->comm_isend.clean_fun = clean_fun;
956 simcall->comm_isend.data = data;
957 simcall->comm_isend.detached = detached;
958 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
959 simcall->comm_isend.result = NULL;
961 SIMIX_simcall_push(simcall->issuer);
962 return simcall->comm_isend.result;
965 * \ingroup simix_comm_management
967 void simcall_comm_recv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
968 int (*match_fun)(void *, void *, smx_action_t), void *data, double timeout)
970 xbt_assert(isfinite(timeout), "timeout is not finite!");
971 xbt_assert(rdv, "No rendez-vous point defined for recv");
973 if (MC_is_active()) {
974 /* the model-checker wants two separate simcalls */
975 smx_action_t comm = simcall_comm_irecv(rdv, dst_buff, dst_buff_size,
977 simcall_comm_wait(comm, timeout);
980 smx_simcall_t simcall = SIMIX_simcall_mine();
982 simcall->call = SIMCALL_COMM_RECV;
983 simcall->comm_recv.rdv = rdv;
984 simcall->comm_recv.dst_buff = dst_buff;
985 simcall->comm_recv.dst_buff_size = dst_buff_size;
986 simcall->comm_recv.match_fun = match_fun;
987 simcall->comm_recv.data = data;
988 simcall->comm_recv.timeout = timeout;
990 SIMIX_simcall_push(simcall->issuer);
994 * \ingroup simix_comm_management
996 smx_action_t simcall_comm_irecv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
997 int (*match_fun)(void *, void *, smx_action_t), void *data)
999 xbt_assert(rdv, "No rendez-vous point defined for irecv");
1001 smx_simcall_t simcall = SIMIX_simcall_mine();
1003 simcall->call = SIMCALL_COMM_IRECV;
1004 simcall->comm_irecv.rdv = rdv;
1005 simcall->comm_irecv.dst_buff = dst_buff;
1006 simcall->comm_irecv.dst_buff_size = dst_buff_size;
1007 simcall->comm_irecv.match_fun = match_fun;
1008 simcall->comm_irecv.data = data;
1009 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1010 simcall->comm_irecv.result = NULL;
1012 SIMIX_simcall_push(simcall->issuer);
1013 return simcall->comm_irecv.result;
1018 * \ingroup simix_comm_management
1020 smx_action_t simcall_comm_iprobe(smx_rdv_t rdv, int src, int tag,
1021 int (*match_fun)(void *, void *, smx_action_t), void *data)
1023 xbt_assert(rdv, "No rendez-vous point defined for iprobe");
1025 smx_simcall_t simcall = SIMIX_simcall_mine();
1027 simcall->call = SIMCALL_COMM_IPROBE;
1028 simcall->comm_iprobe.rdv = rdv;
1029 simcall->comm_iprobe.src = src;
1030 simcall->comm_iprobe.match_fun = match_fun;
1031 simcall->comm_iprobe.data = data;
1032 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1033 simcall->comm_iprobe.result = NULL;
1034 SIMIX_simcall_push(simcall->issuer);
1035 return simcall->comm_iprobe.result;
1039 void simcall_comm_destroy(smx_action_t comm)
1041 xbt_assert(comm, "Invalid parameter");
1043 /* FIXME remove this simcall type: comms are auto-destroyed now */
1046 smx_simcall_t simcall = simcall_mine();
1048 simcall->call = SIMCALL_COMM_DESTROY;
1049 simcall->comm_destroy.comm = comm;
1051 SIMIX_simcall_push(simcall->issuer);
1055 * \ingroup simix_comm_management
1057 void simcall_comm_cancel(smx_action_t comm)
1059 smx_simcall_t simcall = SIMIX_simcall_mine();
1061 simcall->call = SIMCALL_COMM_CANCEL;
1062 simcall->comm_cancel.comm = comm;
1064 SIMIX_simcall_push(simcall->issuer);
1067 * \ingroup simix_comm_management
1069 unsigned int simcall_comm_waitany(xbt_dynar_t comms)
1071 smx_simcall_t simcall = SIMIX_simcall_mine();
1073 simcall->call = SIMCALL_COMM_WAITANY;
1074 simcall->comm_waitany.comms = comms;
1075 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1076 simcall->comm_waitany.result = -1;
1078 SIMIX_simcall_push(simcall->issuer);
1079 return simcall->comm_waitany.result;
1082 * \ingroup simix_comm_management
1084 int simcall_comm_testany(xbt_dynar_t comms)
1086 smx_simcall_t simcall = SIMIX_simcall_mine();
1087 if (xbt_dynar_is_empty(comms))
1090 simcall->call = SIMCALL_COMM_TESTANY;
1091 simcall->comm_testany.comms = comms;
1092 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1093 simcall->comm_testany.result = -1;
1095 SIMIX_simcall_push(simcall->issuer);
1096 return simcall->comm_testany.result;
1099 * \ingroup simix_comm_management
1101 void simcall_comm_wait(smx_action_t comm, double timeout)
1103 xbt_assert(isfinite(timeout), "timeout is not finite!");
1105 smx_simcall_t simcall = SIMIX_simcall_mine();
1107 simcall->call = SIMCALL_COMM_WAIT;
1108 simcall->comm_wait.comm = comm;
1109 simcall->comm_wait.timeout = timeout;
1111 SIMIX_simcall_push(simcall->issuer);
1116 * \brief Set the category of an action.
1118 * This functions changes the category only. It calls a surf function.
1119 * \param execution The execution action
1120 * \param category The tracing category
1122 void simcall_set_category(smx_action_t action, const char *category)
1124 if (category == NULL) {
1128 smx_simcall_t simcall = SIMIX_simcall_mine();
1130 simcall->call = SIMCALL_SET_CATEGORY;
1131 simcall->set_category.action = action;
1132 simcall->set_category.category = category;
1134 SIMIX_simcall_push(simcall->issuer);
1138 * \ingroup simix_comm_management
1141 int simcall_comm_test(smx_action_t comm)
1143 smx_simcall_t simcall = SIMIX_simcall_mine();
1145 simcall->call = SIMCALL_COMM_TEST;
1146 simcall->comm_test.comm = comm;
1147 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1148 simcall->comm_test.result = -1;
1150 SIMIX_simcall_push(simcall->issuer);
1151 return simcall->comm_test.result;
1154 * \ingroup simix_comm_management
1157 double simcall_comm_get_remains(smx_action_t comm)
1159 smx_simcall_t simcall = SIMIX_simcall_mine();
1161 simcall->call = SIMCALL_COMM_GET_REMAINS;
1162 simcall->comm_get_remains.comm = comm;
1163 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1164 simcall->comm_get_remains.result = 0.0;
1166 SIMIX_simcall_push(simcall->issuer);
1167 return simcall->comm_get_remains.result;
1170 * \ingroup simix_comm_management
1173 e_smx_state_t simcall_comm_get_state(smx_action_t comm)
1175 smx_simcall_t simcall = SIMIX_simcall_mine();
1177 simcall->call = SIMCALL_COMM_GET_STATE;
1178 simcall->comm_get_state.comm = comm;
1179 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1180 simcall->comm_get_state.result = -1;
1182 SIMIX_simcall_push(simcall->issuer);
1183 return simcall->comm_get_state.result;
1186 * \ingroup simix_comm_management
1189 void *simcall_comm_get_src_data(smx_action_t comm)
1191 smx_simcall_t simcall = SIMIX_simcall_mine();
1193 simcall->call = SIMCALL_COMM_GET_SRC_DATA;
1194 simcall->comm_get_src_data.comm = comm;
1195 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1196 simcall->comm_get_src_data.result = NULL;
1198 SIMIX_simcall_push(simcall->issuer);
1199 return simcall->comm_get_src_data.result;
1202 * \ingroup simix_comm_management
1205 void *simcall_comm_get_dst_data(smx_action_t comm)
1207 smx_simcall_t simcall = SIMIX_simcall_mine();
1209 simcall->call = SIMCALL_COMM_GET_DST_DATA;
1210 simcall->comm_get_dst_data.comm = comm;
1211 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1212 simcall->comm_get_dst_data.result = NULL;
1214 SIMIX_simcall_push(simcall->issuer);
1215 return simcall->comm_get_dst_data.result;
1218 * \ingroup simix_comm_management
1221 smx_process_t simcall_comm_get_src_proc(smx_action_t comm)
1223 smx_simcall_t simcall = SIMIX_simcall_mine();
1225 simcall->call = SIMCALL_COMM_GET_SRC_PROC;
1226 simcall->comm_get_src_proc.comm = comm;
1227 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1228 simcall->comm_get_src_proc.result = NULL;
1230 SIMIX_simcall_push(simcall->issuer);
1231 return simcall->comm_get_src_proc.result;
1234 * \ingroup simix_comm_management
1237 smx_process_t simcall_comm_get_dst_proc(smx_action_t comm)
1239 smx_simcall_t simcall = SIMIX_simcall_mine();
1241 simcall->call = SIMCALL_COMM_GET_DST_PROC;
1242 simcall->comm_get_dst_proc.comm = comm;
1243 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1244 simcall->comm_get_dst_proc.result = NULL;
1246 SIMIX_simcall_push(simcall->issuer);
1247 return simcall->comm_get_dst_proc.result;
1250 #ifdef HAVE_LATENCY_BOUND_TRACKING
1251 int simcall_comm_is_latency_bounded(smx_action_t comm)
1253 smx_simcall_t simcall = SIMIX_simcall_mine();
1255 simcall->call = SIMCALL_COMM_IS_LATENCY_BOUNDED;
1256 simcall->comm_is_latency_bounded.comm = comm;
1257 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1258 simcall->comm_is_latency_bounded.result = -1;
1260 SIMIX_simcall_push(simcall->issuer);
1261 return simcall->comm_is_latency_bounded.result;
1265 * \ingroup simix_synchro_management
1268 smx_mutex_t simcall_mutex_init(void)
1271 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
1274 smx_simcall_t simcall = SIMIX_simcall_mine();
1276 simcall->call = SIMCALL_MUTEX_INIT;
1277 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1278 simcall->mutex_init.result = NULL;
1280 SIMIX_simcall_push(simcall->issuer);
1281 return simcall->mutex_init.result;
1284 * \ingroup simix_synchro_management
1287 void simcall_mutex_destroy(smx_mutex_t mutex)
1289 smx_simcall_t simcall = SIMIX_simcall_mine();
1291 simcall->call = SIMCALL_MUTEX_DESTROY;
1292 simcall->mutex_destroy.mutex = mutex;
1294 SIMIX_simcall_push(simcall->issuer);
1297 * \ingroup simix_synchro_management
1300 void simcall_mutex_lock(smx_mutex_t mutex)
1302 smx_simcall_t simcall = SIMIX_simcall_mine();
1304 simcall->call = SIMCALL_MUTEX_LOCK;
1305 simcall->mutex_lock.mutex = mutex;
1307 SIMIX_simcall_push(simcall->issuer);
1310 * \ingroup simix_synchro_management
1313 int simcall_mutex_trylock(smx_mutex_t mutex)
1315 smx_simcall_t simcall = SIMIX_simcall_mine();
1317 simcall->call = SIMCALL_MUTEX_TRYLOCK;
1318 simcall->mutex_trylock.mutex = mutex;
1319 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1320 simcall->mutex_trylock.result = -1;
1322 SIMIX_simcall_push(simcall->issuer);
1323 return simcall->mutex_trylock.result;
1326 * \ingroup simix_synchro_management
1329 void simcall_mutex_unlock(smx_mutex_t mutex)
1331 smx_simcall_t simcall = SIMIX_simcall_mine();
1333 simcall->call = SIMCALL_MUTEX_UNLOCK;
1334 simcall->mutex_unlock.mutex = mutex;
1336 SIMIX_simcall_push(simcall->issuer);
1339 * \ingroup simix_synchro_management
1342 smx_cond_t simcall_cond_init(void)
1344 smx_simcall_t simcall = SIMIX_simcall_mine();
1346 simcall->call = SIMCALL_COND_INIT;
1347 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1348 simcall->cond_init.result = NULL;
1350 SIMIX_simcall_push(simcall->issuer);
1351 return simcall->cond_init.result;
1354 * \ingroup simix_synchro_management
1357 void simcall_cond_destroy(smx_cond_t cond)
1359 smx_simcall_t simcall = SIMIX_simcall_mine();
1361 simcall->call = SIMCALL_COND_DESTROY;
1362 simcall->cond_destroy.cond = cond;
1364 SIMIX_simcall_push(simcall->issuer);
1367 * \ingroup simix_synchro_management
1370 void simcall_cond_signal(smx_cond_t cond)
1372 smx_simcall_t simcall = SIMIX_simcall_mine();
1374 simcall->call = SIMCALL_COND_SIGNAL;
1375 simcall->cond_signal.cond = cond;
1377 SIMIX_simcall_push(simcall->issuer);
1380 * \ingroup simix_synchro_management
1383 void simcall_cond_wait(smx_cond_t cond, smx_mutex_t mutex)
1385 smx_simcall_t simcall = SIMIX_simcall_mine();
1387 simcall->call = SIMCALL_COND_WAIT;
1388 simcall->cond_wait.cond = cond;
1389 simcall->cond_wait.mutex = mutex;
1391 SIMIX_simcall_push(simcall->issuer);
1394 * \ingroup simix_synchro_management
1397 void simcall_cond_wait_timeout(smx_cond_t cond,
1401 xbt_assert(isfinite(timeout), "timeout is not finite!");
1403 smx_simcall_t simcall = SIMIX_simcall_mine();
1405 simcall->call = SIMCALL_COND_WAIT_TIMEOUT;
1406 simcall->cond_wait_timeout.cond = cond;
1407 simcall->cond_wait_timeout.mutex = mutex;
1408 simcall->cond_wait_timeout.timeout = timeout;
1410 SIMIX_simcall_push(simcall->issuer);
1413 * \ingroup simix_synchro_management
1416 void simcall_cond_broadcast(smx_cond_t cond)
1418 smx_simcall_t simcall = SIMIX_simcall_mine();
1420 simcall->call = SIMCALL_COND_BROADCAST;
1421 simcall->cond_broadcast.cond = cond;
1423 SIMIX_simcall_push(simcall->issuer);
1426 * \ingroup simix_synchro_management
1429 smx_sem_t simcall_sem_init(int capacity)
1431 smx_simcall_t simcall = SIMIX_simcall_mine();
1433 simcall->call = SIMCALL_SEM_INIT;
1434 simcall->sem_init.capacity = capacity;
1435 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1436 simcall->sem_init.result = NULL;
1438 SIMIX_simcall_push(simcall->issuer);
1439 return simcall->sem_init.result;
1442 * \ingroup simix_synchro_management
1445 void simcall_sem_destroy(smx_sem_t sem)
1447 smx_simcall_t simcall = SIMIX_simcall_mine();
1449 simcall->call = SIMCALL_SEM_DESTROY;
1450 simcall->sem_destroy.sem = sem;
1452 SIMIX_simcall_push(simcall->issuer);
1455 * \ingroup simix_synchro_management
1458 void simcall_sem_release(smx_sem_t sem)
1460 smx_simcall_t simcall = SIMIX_simcall_mine();
1462 simcall->call = SIMCALL_SEM_RELEASE;
1463 simcall->sem_release.sem = sem;
1465 SIMIX_simcall_push(simcall->issuer);
1468 * \ingroup simix_synchro_management
1471 int simcall_sem_would_block(smx_sem_t sem)
1473 smx_simcall_t simcall = SIMIX_simcall_mine();
1475 simcall->call = SIMCALL_SEM_WOULD_BLOCK;
1476 simcall->sem_would_block.sem = sem;
1477 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1478 simcall->sem_would_block.result = -1;
1480 SIMIX_simcall_push(simcall->issuer);
1481 return simcall->sem_would_block.result;
1484 * \ingroup simix_synchro_management
1487 void simcall_sem_acquire(smx_sem_t sem)
1489 smx_simcall_t simcall = SIMIX_simcall_mine();
1491 simcall->call = SIMCALL_SEM_ACQUIRE;
1492 simcall->sem_acquire.sem = sem;
1494 SIMIX_simcall_push(simcall->issuer);
1497 * \ingroup simix_synchro_management
1500 void simcall_sem_acquire_timeout(smx_sem_t sem, double timeout)
1502 xbt_assert(isfinite(timeout), "timeout is not finite!");
1504 smx_simcall_t simcall = SIMIX_simcall_mine();
1506 simcall->call = SIMCALL_SEM_ACQUIRE_TIMEOUT;
1507 simcall->sem_acquire_timeout.sem = sem;
1508 simcall->sem_acquire_timeout.timeout = timeout;
1510 SIMIX_simcall_push(simcall->issuer);
1513 * \ingroup simix_synchro_management
1516 int simcall_sem_get_capacity(smx_sem_t sem)
1518 smx_simcall_t simcall = SIMIX_simcall_mine();
1520 simcall->call = SIMCALL_SEM_GET_CAPACITY;
1521 simcall->sem_get_capacity.sem = sem;
1522 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1523 simcall->sem_get_capacity.result = -1;
1525 SIMIX_simcall_push(simcall->issuer);
1526 return simcall->sem_get_capacity.result;
1529 * \ingroup simix_file_management
1532 double simcall_file_read(void* ptr, size_t size, size_t nmemb, smx_file_t stream)
1534 smx_simcall_t simcall = SIMIX_simcall_mine();
1536 simcall->call = SIMCALL_FILE_READ;
1537 simcall->file_read.ptr = ptr;
1538 simcall->file_read.size = size;
1539 simcall->file_read.nmemb = nmemb;
1540 simcall->file_read.stream = stream;
1541 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1542 simcall->file_read.result = 0.0;
1543 SIMIX_simcall_push(simcall->issuer);
1545 return simcall->file_read.result;
1548 * \ingroup simix_file_management
1551 size_t simcall_file_write(const void* ptr, size_t size, size_t nmemb, smx_file_t stream)
1553 smx_simcall_t simcall = SIMIX_simcall_mine();
1555 simcall->call = SIMCALL_FILE_WRITE;
1556 simcall->file_write.ptr = ptr;
1557 simcall->file_write.size = size;
1558 simcall->file_write.nmemb = nmemb;
1559 simcall->file_write.stream = stream;
1560 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1561 simcall->file_write.result = 0;
1562 SIMIX_simcall_push(simcall->issuer);
1564 return simcall->file_write.result;
1567 * \ingroup simix_file_management
1570 smx_file_t simcall_file_open(const char* mount, const char* path, const char* mode)
1572 smx_simcall_t simcall = SIMIX_simcall_mine();
1574 simcall->call = SIMCALL_FILE_OPEN;
1575 simcall->file_open.mount = mount;
1576 simcall->file_open.path = path;
1577 simcall->file_open.mode = mode;
1578 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1579 simcall->file_open.result = NULL;
1580 SIMIX_simcall_push(simcall->issuer);
1582 return simcall->file_open.result;
1585 * \ingroup simix_file_management
1588 int simcall_file_close(smx_file_t fp)
1590 smx_simcall_t simcall = SIMIX_simcall_mine();
1592 simcall->call = SIMCALL_FILE_CLOSE;
1593 simcall->file_close.fp = fp;
1594 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1595 simcall->file_close.result = -1;
1596 SIMIX_simcall_push(simcall->issuer);
1598 return simcall->file_close.result;
1601 * \ingroup simix_file_management
1604 int simcall_file_stat(smx_file_t fd, s_file_stat_t *buf)
1606 smx_simcall_t simcall = SIMIX_simcall_mine();
1607 simcall->call = SIMCALL_FILE_STAT;
1608 simcall->file_stat.fd = fd;
1609 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1610 simcall->file_stat.result = -1;
1612 SIMIX_simcall_push(simcall->issuer);
1614 *buf = simcall->file_stat.buf;
1616 return simcall->file_stat.result;
1620 * \ingroup simix_file_management
1623 int simcall_file_unlink(smx_file_t fd)
1625 smx_simcall_t simcall = SIMIX_simcall_mine();
1626 simcall->call = SIMCALL_FILE_UNLINK;
1627 simcall->file_unlink.fd = fd;
1628 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1629 simcall->file_unlink.result = -1;
1631 SIMIX_simcall_push(simcall->issuer);
1633 return simcall->file_unlink.result;
1637 * \ingroup simix_file_management
1640 xbt_dict_t simcall_file_ls(const char* mount, const char* path)
1642 smx_simcall_t simcall = SIMIX_simcall_mine();
1643 simcall->call = SIMCALL_FILE_LS;
1644 simcall->file_ls.mount = mount;
1645 simcall->file_ls.path = path;
1646 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1647 simcall->file_ls.result = NULL;
1649 SIMIX_simcall_push(simcall->issuer);
1651 return simcall->file_ls.result;
1656 void *simcall_mc_snapshot(void)
1658 smx_simcall_t simcall = SIMIX_simcall_mine();
1659 simcall->call = SIMCALL_MC_SNAPSHOT;
1661 SIMIX_simcall_push(simcall->issuer);
1663 return simcall->mc_snapshot.s;
1666 int simcall_mc_compare_snapshots(void *s1, void *s2){
1668 smx_simcall_t simcall = SIMIX_simcall_mine();
1669 simcall->call = SIMCALL_MC_COMPARE_SNAPSHOTS;
1670 simcall->mc_compare_snapshots.snapshot1 = s1;
1671 simcall->mc_compare_snapshots.snapshot2 = s2;
1673 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1674 simcall->mc_compare_snapshots.result = -1;
1676 SIMIX_simcall_push(simcall->issuer);
1678 return simcall->mc_compare_snapshots.result;
1681 #endif /* HAVE_MC */
1683 /* ****************************************************************************************** */
1684 /* TUTORIAL: New API */
1685 /* All functions for simcall */
1686 /* ****************************************************************************************** */
1687 int simcall_new_api_fct(const char* param1, double param2){
1688 smx_simcall_t simcall = SIMIX_simcall_mine();
1689 simcall->call = SIMCALL_NEW_API_INIT;
1690 simcall->new_api.param1 = param1;
1691 simcall->new_api.param2 = param2;
1693 SIMIX_simcall_push(simcall->issuer);
1694 return simcall->new_api.result;
1697 /* ************************************************************************** */
1699 /** @brief returns a printable string representing a simcall */
1700 const char *SIMIX_simcall_name(e_smx_simcall_t kind) {
1701 return simcall_names[kind];