1 /* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "msg/private.h"
8 #include "xbt/sysdep.h"
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_gos, msg,
14 "Logging specific to MSG (gos)");
16 /** \ingroup msg_gos_functions
18 * \brief Return the last value returned by a MSG function (except
21 MSG_error_t MSG_get_errno(void)
23 return PROCESS_GET_ERRNO();
26 /** \ingroup msg_gos_functions
27 * \brief Executes a task and waits for its termination.
29 * This function is used for describing the behavior of an agent. It
30 * takes only one parameter.
31 * \param task a #m_task_t to execute on the location on which the
33 * \return #MSG_FATAL if \a task is not properly initialized and
36 MSG_error_t MSG_task_execute(m_task_t task)
38 simdata_task_t simdata = NULL;
39 m_process_t self = MSG_process_self();
40 e_surf_action_state_t state = SURF_ACTION_NOT_IN_THE_SYSTEM;
43 simdata = task->simdata;
45 xbt_assert0(simdata->host_nb==0, "This is a parallel task. Go to hell.");
48 TRACE_msg_task_execute_start (task);
51 xbt_assert1((!simdata->compute) && (task->simdata->refcount == 1),
52 "This task is executed somewhere else. Go fix your code! %d", task->simdata->refcount);
54 DEBUG1("Computing on %s", MSG_process_self()->simdata->m_host->name);
56 if (simdata->computation_amount == 0) {
58 TRACE_msg_task_execute_end (task);
63 SIMIX_mutex_lock(simdata->mutex);
65 SIMIX_action_execute(SIMIX_host_self(), task->name,
66 simdata->computation_amount);
67 SIMIX_action_set_priority(simdata->compute, simdata->priority);
69 /* changed to waiting action since we are always waiting one action (execute, communicate or sleep) */
70 self->simdata->waiting_action = simdata->compute;
71 SIMIX_register_action_to_condition(simdata->compute, simdata->cond);
73 SIMIX_cond_wait(simdata->cond, simdata->mutex);
74 state = SIMIX_action_get_state(simdata->compute);
75 } while (state == SURF_ACTION_READY || state == SURF_ACTION_RUNNING);
76 SIMIX_unregister_action_to_condition(simdata->compute, simdata->cond);
77 self->simdata->waiting_action = NULL;
79 SIMIX_mutex_unlock(simdata->mutex);
82 if (SIMIX_action_get_state(task->simdata->compute) == SURF_ACTION_DONE) {
83 /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
84 SIMIX_action_destroy(task->simdata->compute);
85 simdata->computation_amount = 0.0;
87 simdata->compute = NULL;
89 TRACE_msg_task_execute_end (task);
92 } else if (SIMIX_host_get_state(SIMIX_host_self()) == 0) {
93 /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
94 SIMIX_action_destroy(task->simdata->compute);
96 simdata->compute = NULL;
98 TRACE_msg_task_execute_end (task);
100 MSG_RETURN(MSG_HOST_FAILURE);
102 /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
103 SIMIX_action_destroy(task->simdata->compute);
104 simdata->comm = NULL;
105 simdata->compute = NULL;
107 TRACE_msg_task_execute_end (task);
109 MSG_RETURN(MSG_TASK_CANCELLED);
113 /** \ingroup m_task_management
114 * \brief Creates a new #m_task_t (a parallel one....).
116 * A constructor for #m_task_t taking six arguments and returning the
117 corresponding object.
118 * \param name a name for the object. It is for user-level information
120 * \param host_nb the number of hosts implied in the parallel task.
121 * \param host_list an array of \p host_nb m_host_t.
122 * \param computation_amount an array of \p host_nb
123 doubles. computation_amount[i] is the total number of operations
124 that have to be performed on host_list[i].
125 * \param communication_amount an array of \p host_nb* \p host_nb doubles.
126 * \param data a pointer to any data may want to attach to the new
127 object. It is for user-level information and can be NULL. It can
128 be retrieved with the function \ref MSG_task_get_data.
130 * \return The new corresponding object.
133 MSG_parallel_task_create(const char *name, int host_nb,
134 const m_host_t * host_list,
135 double *computation_amount,
136 double *communication_amount, void *data)
139 simdata_task_t simdata = xbt_new0(s_simdata_task_t, 1);
140 m_task_t task = xbt_new0(s_m_task_t, 1);
141 task->simdata = simdata;
144 task->name = xbt_strdup(name);
148 simdata->computation_amount = 0;
149 simdata->message_size = 0;
150 simdata->cond = SIMIX_cond_init();
151 simdata->mutex = SIMIX_mutex_init();
152 simdata->compute = NULL;
153 simdata->comm = NULL;
154 simdata->rate = -1.0;
155 simdata->refcount = 1;
156 simdata->sender = NULL;
157 simdata->receiver = NULL;
158 simdata->source = NULL;
160 simdata->host_nb = host_nb;
161 simdata->host_list = xbt_new0(smx_host_t, host_nb);
162 simdata->comp_amount = computation_amount;
163 simdata->comm_amount = communication_amount;
165 for (i = 0; i < host_nb; i++)
166 simdata->host_list[i] = host_list[i]->simdata->smx_host;
171 MSG_error_t MSG_parallel_task_execute(m_task_t task)
173 simdata_task_t simdata = NULL;
174 m_process_t self = MSG_process_self();
175 e_surf_action_state_t state = SURF_ACTION_NOT_IN_THE_SYSTEM;
178 simdata = task->simdata;
180 xbt_assert0((!simdata->compute)
181 && (task->simdata->refcount == 1),
182 "This task is executed somewhere else. Go fix your code!");
184 xbt_assert0(simdata->host_nb, "This is not a parallel task. Go to hell.");
186 DEBUG1("Computing on %s", MSG_process_self()->simdata->m_host->name);
190 SIMIX_mutex_lock(simdata->mutex);
192 SIMIX_action_parallel_execute(task->name, simdata->host_nb,
193 simdata->host_list, simdata->comp_amount,
194 simdata->comm_amount, 1.0, -1.0);
196 self->simdata->waiting_action = simdata->compute;
197 SIMIX_register_action_to_condition(simdata->compute, simdata->cond);
199 SIMIX_cond_wait(simdata->cond, simdata->mutex);
200 state = SIMIX_action_get_state(task->simdata->compute);
201 } while (state == SURF_ACTION_READY || state == SURF_ACTION_RUNNING);
203 SIMIX_unregister_action_to_condition(simdata->compute, simdata->cond);
204 self->simdata->waiting_action = NULL;
207 SIMIX_mutex_unlock(simdata->mutex);
210 if (SIMIX_action_get_state(task->simdata->compute) == SURF_ACTION_DONE) {
211 /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
212 SIMIX_action_destroy(task->simdata->compute);
213 simdata->computation_amount = 0.0;
214 simdata->comm = NULL;
215 simdata->compute = NULL;
217 } else if (SIMIX_host_get_state(SIMIX_host_self()) == 0) {
218 /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
219 SIMIX_action_destroy(task->simdata->compute);
220 simdata->comm = NULL;
221 simdata->compute = NULL;
222 MSG_RETURN(MSG_HOST_FAILURE);
224 /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
225 SIMIX_action_destroy(task->simdata->compute);
226 simdata->comm = NULL;
227 simdata->compute = NULL;
228 MSG_RETURN(MSG_TASK_CANCELLED);
234 /** \ingroup msg_gos_functions
235 * \brief Sleep for the specified number of seconds
237 * Makes the current process sleep until \a time seconds have elapsed.
239 * \param nb_sec a number of second
241 MSG_error_t MSG_process_sleep(double nb_sec)
243 smx_action_t act_sleep;
244 m_process_t proc = MSG_process_self();
245 e_surf_action_state_t state = SURF_ACTION_NOT_IN_THE_SYSTEM;
250 TRACE_msg_process_sleep_in (MSG_process_self());
253 /* create action to sleep */
255 SIMIX_action_sleep(SIMIX_process_get_host(proc->simdata->s_process),
258 mutex = SIMIX_mutex_init();
259 SIMIX_mutex_lock(mutex);
261 /* create conditional and register action to it */
262 cond = SIMIX_cond_init();
264 proc->simdata->waiting_action = act_sleep;
265 SIMIX_register_action_to_condition(act_sleep, cond);
267 SIMIX_cond_wait(cond, mutex);
268 state = SIMIX_action_get_state(act_sleep);
269 } while (state == SURF_ACTION_READY || state == SURF_ACTION_RUNNING);
270 proc->simdata->waiting_action = NULL;
271 SIMIX_unregister_action_to_condition(act_sleep, cond);
272 SIMIX_mutex_unlock(mutex);
274 /* remove variables */
275 SIMIX_cond_destroy(cond);
276 SIMIX_mutex_destroy(mutex);
278 if (SIMIX_action_get_state(act_sleep) == SURF_ACTION_DONE) {
279 if (SIMIX_host_get_state(SIMIX_host_self()) == SURF_RESOURCE_OFF) {
280 SIMIX_action_destroy(act_sleep);
282 TRACE_msg_process_sleep_out (MSG_process_self());
284 MSG_RETURN(MSG_HOST_FAILURE);
287 SIMIX_action_destroy(act_sleep);
289 TRACE_msg_process_sleep_out (MSG_process_self());
291 MSG_RETURN(MSG_HOST_FAILURE);
294 SIMIX_action_destroy(act_sleep);
296 TRACE_msg_process_sleep_out (MSG_process_self());
301 /** \ingroup msg_gos_functions
302 * \brief Listen on \a channel and waits for receiving a task from \a host.
304 * It takes three parameters.
305 * \param task a memory location for storing a #m_task_t. It will
306 hold a task when this function will return. Thus \a task should not
307 be equal to \c NULL and \a *task should be equal to \c NULL. If one of
308 those two condition does not hold, there will be a warning message.
309 * \param channel the channel on which the agent should be
310 listening. This value has to be >=0 and < than the maximal
311 number of channels fixed with MSG_set_channel_number().
312 * \param host the host that is to be watched.
313 * \return #MSG_FATAL if \a task is equal to \c NULL, #MSG_WARNING
314 if \a *task is not equal to \c NULL, and #MSG_OK otherwise.
317 MSG_task_get_from_host(m_task_t * task, m_channel_t channel, m_host_t host)
319 return MSG_task_get_ext(task, channel, -1, host);
322 /** \ingroup msg_gos_functions
323 * \brief Listen on a channel and wait for receiving a task.
325 * It takes two parameters.
326 * \param task a memory location for storing a #m_task_t. It will
327 hold a task when this function will return. Thus \a task should not
328 be equal to \c NULL and \a *task should be equal to \c NULL. If one of
329 those two condition does not hold, there will be a warning message.
330 * \param channel the channel on which the agent should be
331 listening. This value has to be >=0 and < than the maximal
332 number of channels fixed with MSG_set_channel_number().
333 * \return #MSG_FATAL if \a task is equal to \c NULL, #MSG_WARNING
334 * if \a *task is not equal to \c NULL, and #MSG_OK otherwise.
336 MSG_error_t MSG_task_get(m_task_t * task, m_channel_t channel)
338 return MSG_task_get_with_timeout(task, channel, -1);
341 /** \ingroup msg_gos_functions
342 * \brief Listen on a channel and wait for receiving a task with a timeout.
344 * It takes three parameters.
345 * \param task a memory location for storing a #m_task_t. It will
346 hold a task when this function will return. Thus \a task should not
347 be equal to \c NULL and \a *task should be equal to \c NULL. If one of
348 those two condition does not hold, there will be a warning message.
349 * \param channel the channel on which the agent should be
350 listening. This value has to be >=0 and < than the maximal
351 number of channels fixed with MSG_set_channel_number().
352 * \param max_duration the maximum time to wait for a task before giving
353 up. In such a case, #MSG_TRANSFER_FAILURE will be returned, \a task
354 will not be modified and will still be
355 equal to \c NULL when returning.
356 * \return #MSG_FATAL if \a task is equal to \c NULL, #MSG_WARNING
357 if \a *task is not equal to \c NULL, and #MSG_OK otherwise.
360 MSG_task_get_with_timeout(m_task_t * task, m_channel_t channel,
363 return MSG_task_get_ext(task, channel, max_duration, NULL);
366 /** \defgroup msg_gos_functions MSG Operating System Functions
367 * \brief This section describes the functions that can be used
368 * by an agent for handling some task.
372 MSG_task_get_ext(m_task_t * task, m_channel_t channel, double timeout,
375 xbt_assert1((channel >= 0)
376 && (channel < msg_global->max_channel), "Invalid channel %d",
380 MSG_mailbox_get_task_ext(MSG_mailbox_get_by_channel
381 (MSG_host_self(), channel), task, host, timeout);
385 MSG_task_receive_from_host(m_task_t * task, const char *alias, m_host_t host)
387 return MSG_task_receive_ext(task, alias, -1, host);
390 MSG_error_t MSG_task_receive(m_task_t * task, const char *alias)
392 return MSG_task_receive_with_timeout(task, alias, -1);
396 MSG_task_receive_with_timeout(m_task_t * task, const char *alias,
399 return MSG_task_receive_ext(task, alias, timeout, NULL);
403 MSG_task_receive_ext(m_task_t * task, const char *alias, double timeout,
406 return MSG_mailbox_get_task_ext(MSG_mailbox_get_by_alias(alias), task, host,
410 msg_comm_t MSG_task_isend(m_task_t task, const char *alias) {
411 simdata_task_t t_simdata = NULL;
412 m_process_t process = MSG_process_self();
413 msg_mailbox_t mailbox = MSG_mailbox_get_by_alias(alias);
417 /* FIXME: these functions are not tracable */
419 /* Prepare the task to send */
420 t_simdata = task->simdata;
421 t_simdata->sender = process;
422 t_simdata->source = MSG_host_self();
424 xbt_assert0(t_simdata->refcount == 1,
425 "This task is still being used somewhere else. You cannot send it now. Go fix your code!");
427 t_simdata->refcount++;
428 msg_global->sent_msg++;
429 process->simdata->waiting_task = task;
431 /* Send it by calling SIMIX network layer */
433 /* Kept for semantical compatibility with older implementation */
435 SIMIX_cond_signal(mailbox->cond);
437 return SIMIX_network_isend(mailbox->rdv, t_simdata->message_size, t_simdata->rate,
438 task, sizeof(void*), &t_simdata->comm);
441 msg_comm_t MSG_task_irecv(m_task_t * task, const char *alias) {
443 smx_rdv_t rdv = MSG_mailbox_get_by_alias(alias)->rdv;
444 msg_mailbox_t mailbox=MSG_mailbox_get_by_alias(alias);
445 size_t size = sizeof(void*);
449 /* FIXME: these functions are not tracable */
451 memset(&comm,0,sizeof(comm));
453 /* Kept for compatibility with older implementation */
454 xbt_assert1(!MSG_mailbox_get_cond(mailbox),
455 "A process is already blocked on this channel %s",
456 MSG_mailbox_get_alias(mailbox));
459 xbt_assert0(task, "Null pointer for the task storage");
462 CRITICAL0("MSG_task_get() was asked to write in a non empty task struct.");
464 /* Try to receive it by calling SIMIX network layer */
465 return SIMIX_network_irecv(rdv, task, &size);
467 int MSG_comm_test(msg_comm_t comm) {
468 return SIMIX_network_test(comm);
471 MSG_error_t MSG_comm_wait(msg_comm_t comm, double timeout) {
473 MSG_error_t res = MSG_OK;
475 SIMIX_network_wait(comm,timeout);
477 if(!(comm->src_proc == SIMIX_process_self()))
480 task = (m_task_t) SIMIX_communication_get_src_buf(comm);
481 task->simdata->refcount--;
484 /* FIXME: these functions are not tracable */
488 res = MSG_HOST_FAILURE;
491 res = MSG_TRANSFER_FAILURE;
497 xbt_die(bprintf("Unhandled SIMIX network exception: %s",e.msg));
504 /** \ingroup msg_gos_functions
505 * \brief Put a task on a channel of an host and waits for the end of the
508 * This function is used for describing the behavior of an agent. It
509 * takes three parameter.
510 * \param task a #m_task_t to send on another location. This task
511 will not be usable anymore when the function will return. There is
512 no automatic task duplication and you have to save your parameters
513 before calling this function. Tasks are unique and once it has been
514 sent to another location, you should not access it anymore. You do
515 not need to call MSG_task_destroy() but to avoid using, as an
516 effect of inattention, this task anymore, you definitely should
517 renitialize it with #MSG_TASK_UNINITIALIZED. Note that this task
518 can be transfered iff it has been correctly created with
520 * \param dest the destination of the message
521 * \param channel the channel on which the agent should put this
522 task. This value has to be >=0 and < than the maximal number of
523 channels fixed with MSG_set_channel_number().
524 * \return #MSG_FATAL if \a task is not properly initialized and
525 * #MSG_OK otherwise. Returns #MSG_HOST_FAILURE if the host on which
526 * this function was called was shut down. Returns
527 * #MSG_TRANSFER_FAILURE if the transfer could not be properly done
528 * (network failure, dest failure)
530 MSG_error_t MSG_task_put(m_task_t task, m_host_t dest, m_channel_t channel)
532 return MSG_task_put_with_timeout(task, dest, channel, -1.0);
535 /** \ingroup msg_gos_functions
536 * \brief Does exactly the same as MSG_task_put but with a bounded transmition
542 MSG_task_put_bounded(m_task_t task, m_host_t dest, m_channel_t channel,
545 task->simdata->rate = maxrate;
546 return MSG_task_put(task, dest, channel);
549 /** \ingroup msg_gos_functions \brief Put a task on a channel of an
550 * host (with a timeout on the waiting of the destination host) and
551 * waits for the end of the transmission.
553 * This function is used for describing the behavior of an agent. It
554 * takes four parameter.
555 * \param task a #m_task_t to send on another location. This task
556 will not be usable anymore when the function will return. There is
557 no automatic task duplication and you have to save your parameters
558 before calling this function. Tasks are unique and once it has been
559 sent to another location, you should not access it anymore. You do
560 not need to call MSG_task_destroy() but to avoid using, as an
561 effect of inattention, this task anymore, you definitely should
562 renitialize it with #MSG_TASK_UNINITIALIZED. Note that this task
563 can be transfered iff it has been correctly created with
565 * \param dest the destination of the message
566 * \param channel the channel on which the agent should put this
567 task. This value has to be >=0 and < than the maximal number of
568 channels fixed with MSG_set_channel_number().
569 * \param timeout the maximum time to wait for a task before giving
570 up. In such a case, #MSG_TRANSFER_FAILURE will be returned, \a task
572 * \return #MSG_FATAL if \a task is not properly initialized and
573 #MSG_OK otherwise. Returns #MSG_HOST_FAILURE if the host on which
574 this function was called was shut down. Returns
575 #MSG_TRANSFER_FAILURE if the transfer could not be properly done
576 (network failure, dest failure, timeout...)
579 MSG_task_put_with_timeout(m_task_t task, m_host_t dest, m_channel_t channel,
582 xbt_assert1((channel >= 0)
583 && (channel < msg_global->max_channel), "Invalid channel %d",
587 MSG_mailbox_put_with_timeout(MSG_mailbox_get_by_channel(dest, channel),
591 MSG_error_t MSG_task_send(m_task_t task, const char *alias)
593 return MSG_task_send_with_timeout(task, alias, -1);
598 MSG_task_send_bounded(m_task_t task, const char *alias, double maxrate)
600 task->simdata->rate = maxrate;
601 return MSG_task_send(task, alias);
606 MSG_task_send_with_timeout(m_task_t task, const char *alias, double timeout)
608 return MSG_mailbox_put_with_timeout(MSG_mailbox_get_by_alias(alias), task,
612 int MSG_task_listen(const char *alias)
616 return !MSG_mailbox_is_empty(MSG_mailbox_get_by_alias(alias));
619 /** \ingroup msg_gos_functions
620 * \brief Test whether there is a pending communication on a channel.
622 * It takes one parameter.
623 * \param channel the channel on which the agent should be
624 listening. This value has to be >=0 and < than the maximal
625 number of channels fixed with MSG_set_channel_number().
626 * \return 1 if there is a pending communication and 0 otherwise
628 int MSG_task_Iprobe(m_channel_t channel)
630 xbt_assert1((channel >= 0)
631 && (channel < msg_global->max_channel), "Invalid channel %d",
637 !MSG_mailbox_is_empty(MSG_mailbox_get_by_channel
638 (MSG_host_self(), channel));
641 /** \ingroup msg_gos_functions
643 * \brief Return the number of tasks waiting to be received on a \a
644 channel and sent by \a host.
646 * It takes two parameters.
647 * \param channel the channel on which the agent should be
648 listening. This value has to be >=0 and < than the maximal
649 number of channels fixed with MSG_set_channel_number().
650 * \param host the host that is to be watched.
651 * \return the number of tasks waiting to be received on \a channel
654 int MSG_task_probe_from_host(int channel, m_host_t host)
656 xbt_assert1((channel >= 0)
657 && (channel < msg_global->max_channel), "Invalid channel %d",
663 MSG_mailbox_get_count_host_waiting_tasks(MSG_mailbox_get_by_channel
664 (MSG_host_self(), channel),
669 int MSG_task_listen_from_host(const char *alias, m_host_t host)
674 MSG_mailbox_get_count_host_waiting_tasks(MSG_mailbox_get_by_alias(alias),
678 /** \ingroup msg_gos_functions
679 * \brief Test whether there is a pending communication on a channel, and who sent it.
681 * It takes one parameter.
682 * \param channel the channel on which the agent should be
683 listening. This value has to be >=0 and < than the maximal
684 number of channels fixed with MSG_set_channel_number().
685 * \return -1 if there is no pending communication and the PID of the process who sent it otherwise
687 int MSG_task_probe_from(m_channel_t channel)
693 xbt_assert1((channel >= 0)
694 && (channel < msg_global->max_channel), "Invalid channel %d",
699 MSG_mailbox_get_head(MSG_mailbox_get_by_channel
700 (MSG_host_self(), channel))))
703 return MSG_process_get_PID(task->simdata->sender);
706 int MSG_task_listen_from(const char *alias)
712 if (NULL == (task = MSG_mailbox_get_head(MSG_mailbox_get_by_alias(alias))))
715 return MSG_process_get_PID(task->simdata->sender);
718 /** \ingroup msg_gos_functions
719 * \brief Wait for at most \a max_duration second for a task reception
722 * \a PID is updated with the PID of the first process that triggered this event if any.
724 * It takes three parameters:
725 * \param channel the channel on which the agent should be
726 listening. This value has to be >=0 and < than the maximal.
727 number of channels fixed with MSG_set_channel_number().
728 * \param PID a memory location for storing an int.
729 * \param timeout the maximum time to wait for a task before
730 giving up. In the case of a reception, *\a PID will be updated
731 with the PID of the first process to send a task.
732 * \return #MSG_HOST_FAILURE if the host is shut down in the meantime
733 and #MSG_OK otherwise.
736 MSG_channel_select_from(m_channel_t channel, double timeout, int *PID)
739 simdata_host_t h_simdata = NULL;
743 msg_mailbox_t mailbox;
745 xbt_assert1((channel >= 0)
746 && (channel < msg_global->max_channel), "Invalid channel %d",
753 if (timeout == 0.0) {
754 *PID = MSG_task_probe_from(channel);
759 h_simdata = h->simdata;
761 mailbox = MSG_mailbox_get_by_channel(MSG_host_self(), channel);
763 while (MSG_mailbox_is_empty(mailbox)) {
770 SIMIX_mutex_lock(h_simdata->mutex);
772 xbt_assert1(!MSG_mailbox_get_cond(mailbox),
773 "A process is already blocked on this channel %d", channel);
775 cond = SIMIX_cond_init();
777 MSG_mailbox_set_cond(mailbox, cond);
780 SIMIX_cond_wait_timeout(cond, h_simdata->mutex, timeout);
782 SIMIX_cond_wait(cond, h_simdata->mutex);
785 SIMIX_cond_destroy(cond);
786 SIMIX_mutex_unlock(h_simdata->mutex);
788 if (SIMIX_host_get_state(h_simdata->smx_host) == 0) {
789 MSG_RETURN(MSG_HOST_FAILURE);
792 MSG_mailbox_set_cond(mailbox, NULL);
796 if (NULL == (t = MSG_mailbox_get_head(mailbox)))
801 *PID = MSG_process_get_PID(t->simdata->sender);
809 MSG_error_t MSG_alias_select_from(const char *alias, double timeout, int *PID)
812 simdata_host_t h_simdata = NULL;
816 msg_mailbox_t mailbox;
822 if (timeout == 0.0) {
823 *PID = MSG_task_listen_from(alias);
828 h_simdata = h->simdata;
830 DEBUG2("Probing on alias %s (%s)", alias, h->name);
832 mailbox = MSG_mailbox_get_by_alias(alias);
834 while (MSG_mailbox_is_empty(mailbox)) {
841 SIMIX_mutex_lock(h_simdata->mutex);
843 xbt_assert1(!MSG_mailbox_get_cond(mailbox),
844 "A process is already blocked on this alias %s", alias);
846 cond = SIMIX_cond_init();
848 MSG_mailbox_set_cond(mailbox, cond);
851 SIMIX_cond_wait_timeout(cond, h_simdata->mutex, timeout);
853 SIMIX_cond_wait(cond, h_simdata->mutex);
856 SIMIX_cond_destroy(cond);
857 SIMIX_mutex_unlock(h_simdata->mutex);
859 if (SIMIX_host_get_state(h_simdata->smx_host) == 0) {
860 MSG_RETURN(MSG_HOST_FAILURE);
863 MSG_mailbox_set_cond(mailbox, NULL);
867 if (NULL == (t = MSG_mailbox_get_head(mailbox)))
872 *PID = MSG_process_get_PID(t->simdata->sender);