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. */
8 #include "xbt/sysdep.h"
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_gos, msg,
15 "Logging specific to MSG (gos)");
17 /** \ingroup msg_gos_functions
19 * \brief Return the last value returned by a MSG function (except
22 MSG_error_t MSG_get_errno(void)
24 return PROCESS_GET_ERRNO();
27 /** \ingroup msg_gos_functions
28 * \brief Executes a task and waits for its termination.
30 * This function is used for describing the behavior of an agent. It
31 * takes only one parameter.
32 * \param task a #m_task_t to execute on the location on which the
34 * \return #MSG_FATAL if \a task is not properly initialized and
37 MSG_error_t MSG_task_execute(m_task_t task)
39 simdata_task_t simdata = NULL;
40 simdata_process_t p_simdata;
41 e_smx_state_t comp_state;
44 simdata = task->simdata;
46 xbt_assert0(simdata->host_nb == 0,
47 "This is a parallel task. Go to hell.");
50 TRACE_msg_task_execute_start(task);
53 xbt_assert1((!simdata->compute) && (task->simdata->isused == 0),
54 "This task is executed somewhere else. Go fix your code! %d",
55 task->simdata->isused);
57 XBT_DEBUG("Computing on %s", MSG_process_get_name(MSG_process_self()));
59 if (simdata->computation_amount == 0) {
61 TRACE_msg_task_execute_end(task);
67 SIMIX_req_host_execute(task->name, SIMIX_host_self(),
68 simdata->computation_amount,
71 SIMIX_req_set_category(simdata->compute, task->category);
74 p_simdata = SIMIX_process_self_get_data();
75 p_simdata->waiting_action = simdata->compute;
76 comp_state = SIMIX_req_host_execution_wait(simdata->compute);
77 p_simdata->waiting_action = NULL;
81 XBT_DEBUG("Execution task '%s' finished in state %d", task->name, comp_state);
82 if (comp_state == SIMIX_DONE) {
83 /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
84 simdata->computation_amount = 0.0;
86 simdata->compute = NULL;
88 TRACE_msg_task_execute_end(task);
91 } else if (SIMIX_req_host_get_state(SIMIX_host_self()) == 0) {
92 /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
94 simdata->compute = NULL;
96 TRACE_msg_task_execute_end(task);
98 MSG_RETURN(MSG_HOST_FAILURE);
100 /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
101 simdata->comm = NULL;
102 simdata->compute = NULL;
104 TRACE_msg_task_execute_end(task);
106 MSG_RETURN(MSG_TASK_CANCELLED);
110 /** \ingroup m_task_management
111 * \brief Creates a new #m_task_t (a parallel one....).
113 * A constructor for #m_task_t taking six arguments and returning the
114 corresponding object.
115 * \param name a name for the object. It is for user-level information
117 * \param host_nb the number of hosts implied in the parallel task.
118 * \param host_list an array of \p host_nb m_host_t.
119 * \param computation_amount an array of \p host_nb
120 doubles. computation_amount[i] is the total number of operations
121 that have to be performed on host_list[i].
122 * \param communication_amount an array of \p host_nb* \p host_nb doubles.
123 * \param data a pointer to any data may want to attach to the new
124 object. It is for user-level information and can be NULL. It can
125 be retrieved with the function \ref MSG_task_get_data.
127 * \return The new corresponding object.
130 MSG_parallel_task_create(const char *name, int host_nb,
131 const m_host_t * host_list,
132 double *computation_amount,
133 double *communication_amount, void *data)
136 simdata_task_t simdata = xbt_new0(s_simdata_task_t, 1);
137 m_task_t task = xbt_new0(s_m_task_t, 1);
138 task->simdata = simdata;
141 task->name = xbt_strdup(name);
145 simdata->computation_amount = 0;
146 simdata->message_size = 0;
147 simdata->compute = NULL;
148 simdata->comm = NULL;
149 simdata->rate = -1.0;
151 simdata->sender = NULL;
152 simdata->receiver = NULL;
153 simdata->source = NULL;
155 simdata->host_nb = host_nb;
156 simdata->host_list = xbt_new0(smx_host_t, host_nb);
157 simdata->comp_amount = computation_amount;
158 simdata->comm_amount = communication_amount;
160 for (i = 0; i < host_nb; i++)
161 simdata->host_list[i] = host_list[i]->simdata->smx_host;
166 MSG_error_t MSG_parallel_task_execute(m_task_t task)
168 simdata_task_t simdata = NULL;
169 e_smx_state_t comp_state;
170 simdata_process_t p_simdata;
173 simdata = task->simdata;
174 p_simdata = SIMIX_process_self_get_data();
176 xbt_assert0((!simdata->compute)
177 && (task->simdata->isused == 0),
178 "This task is executed somewhere else. Go fix your code!");
180 xbt_assert0(simdata->host_nb,
181 "This is not a parallel task. Go to hell.");
183 XBT_DEBUG("Parallel computing on %s", p_simdata->m_host->name);
188 SIMIX_req_host_parallel_execute(task->name, simdata->host_nb,
190 simdata->comp_amount,
191 simdata->comm_amount, 1.0, -1.0);
192 XBT_DEBUG("Parallel execution action created: %p", simdata->compute);
194 p_simdata->waiting_action = simdata->compute;
195 comp_state = SIMIX_req_host_execution_wait(simdata->compute);
196 p_simdata->waiting_action = NULL;
198 XBT_DEBUG("Finished waiting for execution of action %p, state = %d", simdata->compute, comp_state);
202 if (comp_state == SIMIX_DONE) {
203 /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
204 simdata->computation_amount = 0.0;
205 simdata->comm = NULL;
206 simdata->compute = NULL;
208 } else if (SIMIX_req_host_get_state(SIMIX_host_self()) == 0) {
209 /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
210 simdata->comm = NULL;
211 simdata->compute = NULL;
212 MSG_RETURN(MSG_HOST_FAILURE);
214 /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
215 simdata->comm = NULL;
216 simdata->compute = NULL;
217 MSG_RETURN(MSG_TASK_CANCELLED);
222 /** \ingroup msg_gos_functions
223 * \brief Sleep for the specified number of seconds
225 * Makes the current process sleep until \a time seconds have elapsed.
227 * \param nb_sec a number of second
229 MSG_error_t MSG_process_sleep(double nb_sec)
232 /*m_process_t proc = MSG_process_self();*/
235 TRACE_msg_process_sleep_in(MSG_process_self());
238 /* create action to sleep */
239 state = SIMIX_req_process_sleep(nb_sec);
241 /*proc->simdata->waiting_action = act_sleep;
243 FIXME: check if not setting the waiting_action breaks something on msg
245 proc->simdata->waiting_action = NULL;*/
247 if (state == SIMIX_DONE) {
249 TRACE_msg_process_sleep_out(MSG_process_self());
254 TRACE_msg_process_sleep_out(MSG_process_self());
256 MSG_RETURN(MSG_HOST_FAILURE);
260 /** \ingroup msg_gos_functions
261 * \brief Listen on \a channel and waits for receiving a task from \a host.
263 * It takes three parameters.
264 * \param task a memory location for storing a #m_task_t. It will
265 hold a task when this function will return. Thus \a task should not
266 be equal to \c NULL and \a *task should be equal to \c NULL. If one of
267 those two condition does not hold, there will be a warning message.
268 * \param channel the channel on which the agent should be
269 listening. This value has to be >=0 and < than the maximal
270 number of channels fixed with MSG_set_channel_number().
271 * \param host the host that is to be watched.
272 * \return #MSG_FATAL if \a task is equal to \c NULL, #MSG_WARNING
273 if \a *task is not equal to \c NULL, and #MSG_OK otherwise.
276 MSG_task_get_from_host(m_task_t * task, m_channel_t channel, m_host_t host)
278 return MSG_task_get_ext(task, channel, -1, host);
281 /** \ingroup msg_gos_functions
282 * \brief Listen on a channel and wait for receiving a task.
284 * It takes two parameters.
285 * \param task a memory location for storing a #m_task_t. It will
286 hold a task when this function will return. Thus \a task should not
287 be equal to \c NULL and \a *task should be equal to \c NULL. If one of
288 those two condition does not hold, there will be a warning message.
289 * \param channel the channel on which the agent should be
290 listening. This value has to be >=0 and < than the maximal
291 number of channels fixed with MSG_set_channel_number().
292 * \return #MSG_FATAL if \a task is equal to \c NULL, #MSG_WARNING
293 * if \a *task is not equal to \c NULL, and #MSG_OK otherwise.
295 MSG_error_t MSG_task_get(m_task_t * task, m_channel_t channel)
297 return MSG_task_get_with_timeout(task, channel, -1);
300 /** \ingroup msg_gos_functions
301 * \brief Listen on a channel and wait for receiving a task with a timeout.
303 * It takes three parameters.
304 * \param task a memory location for storing a #m_task_t. It will
305 hold a task when this function will return. Thus \a task should not
306 be equal to \c NULL and \a *task should be equal to \c NULL. If one of
307 those two condition does not hold, there will be a warning message.
308 * \param channel the channel on which the agent should be
309 listening. This value has to be >=0 and < than the maximal
310 number of channels fixed with MSG_set_channel_number().
311 * \param max_duration the maximum time to wait for a task before giving
312 up. In such a case, #MSG_TRANSFER_FAILURE will be returned, \a task
313 will not be modified and will still be
314 equal to \c NULL when returning.
315 * \return #MSG_FATAL if \a task is equal to \c NULL, #MSG_WARNING
316 if \a *task is not equal to \c NULL, and #MSG_OK otherwise.
319 MSG_task_get_with_timeout(m_task_t * task, m_channel_t channel,
322 return MSG_task_get_ext(task, channel, max_duration, NULL);
325 /** \defgroup msg_gos_functions MSG Operating System Functions
326 * \brief This section describes the functions that can be used
327 * by an agent for handling some task.
331 MSG_task_get_ext(m_task_t * task, m_channel_t channel, double timeout,
334 xbt_assert1((channel >= 0)
335 && (channel < msg_global->max_channel), "Invalid channel %d",
339 MSG_mailbox_get_task_ext(MSG_mailbox_get_by_channel
340 (MSG_host_self(), channel), task, host,
345 MSG_task_receive_from_host(m_task_t * task, const char *alias,
348 return MSG_task_receive_ext(task, alias, -1, host);
351 MSG_error_t MSG_task_receive(m_task_t * task, const char *alias)
353 return MSG_task_receive_with_timeout(task, alias, -1);
357 MSG_task_receive_with_timeout(m_task_t * task, const char *alias,
360 return MSG_task_receive_ext(task, alias, timeout, NULL);
364 MSG_task_receive_ext(m_task_t * task, const char *alias, double timeout,
368 ("MSG_task_receive_ext: Trying to receive a message on mailbox '%s'",
370 return MSG_mailbox_get_task_ext(MSG_mailbox_get_by_alias(alias), task,
374 /** \ingroup msg_gos_functions
375 * \brief Sends a task on a mailbox.
377 * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test()
378 * to end the communication.
380 * \param task a #m_task_t to send on another location.
381 * \param alias name of the mailbox to sent the task to
382 * \return the msg_comm_t communication created
384 msg_comm_t MSG_task_isend(m_task_t task, const char *alias)
386 simdata_task_t t_simdata = NULL;
387 m_process_t process = MSG_process_self();
388 msg_mailbox_t mailbox = MSG_mailbox_get_by_alias(alias);
392 /* FIXME: these functions are not traceable */
394 /* Prepare the task to send */
395 t_simdata = task->simdata;
396 t_simdata->sender = process;
397 t_simdata->source = MSG_host_self();
399 xbt_assert0(t_simdata->isused == 0,
400 "This task is still being used somewhere else. You cannot send it now. Go fix your code!");
402 t_simdata->isused = 1;
403 msg_global->sent_msg++;
405 /* Send it by calling SIMIX network layer */
406 msg_comm_t comm = xbt_new0(s_msg_comm_t, 1);
407 comm->task_sent = task;
408 comm->task_received = NULL;
409 comm->status = MSG_OK;
411 SIMIX_req_comm_isend(mailbox, t_simdata->message_size,
412 t_simdata->rate, task, sizeof(void *), NULL, NULL, 0);
413 t_simdata->comm = comm->s_comm; /* FIXME: is the field t_simdata->comm still useful? */
418 /** \ingroup msg_gos_functions
419 * \brief Sends a task on a mailbox.
421 * This is a non blocking detached send function.
422 * Think of it as a best effort send. The communication
423 * object will be destroyed by the receiver (if any).
425 * \param task a #m_task_t to send on another location.
426 * \param alias name of the mailbox to sent the task to
427 * \param cleanup a function to destroy the task if the
428 * communication fails (if NULL, MSG_task_destroy() will
429 * be used by default)
431 void MSG_task_dsend(m_task_t task, const char *alias, void_f_pvoid_t cleanup)
433 simdata_task_t t_simdata = NULL;
434 m_process_t process = MSG_process_self();
435 msg_mailbox_t mailbox = MSG_mailbox_get_by_alias(alias);
439 if (cleanup == NULL) {
440 cleanup = (void_f_pvoid_t) MSG_task_destroy;
443 /* FIXME: these functions are not traceable */
445 /* Prepare the task to send */
446 t_simdata = task->simdata;
447 t_simdata->sender = process;
448 t_simdata->source = MSG_host_self();
450 xbt_assert0(t_simdata->isused == 0,
451 "This task is still being used somewhere else. You cannot send it now. Go fix your code!");
453 t_simdata->isused = 1;
454 msg_global->sent_msg++;
456 /* Send it by calling SIMIX network layer */
457 SIMIX_req_comm_isend(mailbox, t_simdata->message_size,
458 t_simdata->rate, task, sizeof(void *), NULL, cleanup, 1);
461 /** \ingroup msg_gos_functions
462 * \brief Starts listening for receiving a task from an asynchronous communication.
464 * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test()
465 * to end the communication.
467 * \param task a memory location for storing a #m_task_t.
468 * \param name of the mailbox to receive the task on
469 * \return the msg_comm_t communication created
471 msg_comm_t MSG_task_irecv(m_task_t *task, const char *alias)
473 smx_rdv_t rdv = MSG_mailbox_get_by_alias(alias);
477 /* FIXME: these functions are not tracable */
480 xbt_assert0(task, "Null pointer for the task storage");
484 ("MSG_task_get() was asked to write in a non empty task struct.");
486 /* Try to receive it by calling SIMIX network layer */
487 msg_comm_t comm = xbt_new0(s_msg_comm_t, 1);
488 comm->task_sent = NULL;
489 comm->task_received = task;
490 comm->status = MSG_OK;
491 comm->s_comm = SIMIX_req_comm_irecv(rdv, task, NULL, NULL, NULL);
496 /** \ingroup msg_gos_functions
497 * \brief Checks whether a communication is done, and if yes, finalizes it.
498 * \param comm the communication to test
499 * \return TRUE if the communication is finished
500 * (but it may have failed, use MSG_comm_get_status() to know its status)
501 * or FALSE if the communication is not finished yet
502 * If the status is FALSE, don't forget to use MSG_process_sleep() after the test.
504 int MSG_comm_test(msg_comm_t comm)
509 finished = SIMIX_req_comm_test(comm->s_comm);
512 switch (e.category) {
515 comm->status = MSG_HOST_FAILURE;
520 comm->status = MSG_TRANSFER_FAILURE;
525 comm->status = MSG_TIMEOUT;
538 /** \ingroup msg_gos_functions
539 * \brief This function checks if a communication is finished.
540 * \param comms a vector of communications
541 * \return the position of the finished communication if any
542 * (but it may have failed, use MSG_comm_get_status() to know its status),
543 * or -1 if none is finished
545 int MSG_comm_testany(xbt_dynar_t comms)
548 int finished_index = -1;
550 /* create the equivalent dynar with SIMIX objects */
551 xbt_dynar_t s_comms = xbt_dynar_new(sizeof(smx_action_t), NULL);
554 xbt_dynar_foreach(comms, cursor, comm) {
555 xbt_dynar_push(s_comms, &comm->s_comm);
558 MSG_error_t status = MSG_OK;
560 finished_index = SIMIX_req_comm_testany(s_comms);
563 switch (e.category) {
566 finished_index = e.value;
567 status = MSG_HOST_FAILURE;
571 finished_index = e.value;
572 status = MSG_TRANSFER_FAILURE;
576 finished_index = e.value;
577 status = MSG_TIMEOUT;
585 xbt_dynar_free(&s_comms);
587 if (finished_index != -1) {
588 comm = xbt_dynar_get_as(comms, finished_index, msg_comm_t);
589 /* the communication is finished */
590 comm->status = status;
593 return finished_index;
596 /** \ingroup msg_gos_functions
597 * \brief Destroys a communication.
598 * \param comm the communication to destroy.
600 void MSG_comm_destroy(msg_comm_t comm)
602 if (comm->task_received != NULL
603 && *comm->task_received != NULL
604 && MSG_comm_get_status(comm) == MSG_OK) {
605 (*comm->task_received)->simdata->isused = 0;
608 /* FIXME auto-destroy comms from SIMIX to avoid this request */
609 /*SIMIX_req_comm_destroy(comm->s_comm);*/
613 /** \ingroup msg_gos_functions
614 * \brief Wait for the completion of a communication.
616 * It takes two parameters.
617 * \param comm the communication to wait.
618 * \param timeout Wait until the communication terminates or the timeout occurs
619 * \return MSG_error_t
621 MSG_error_t MSG_comm_wait(msg_comm_t comm, double timeout)
625 SIMIX_req_comm_wait(comm->s_comm, timeout);
627 if (comm->task_received != NULL) {
628 /* I am the receiver */
629 (*comm->task_received)->simdata->isused = 0;
632 /* FIXME: these functions are not traceable */
635 switch (e.category) {
637 comm->status = MSG_HOST_FAILURE;
640 comm->status = MSG_TRANSFER_FAILURE;
643 comm->status = MSG_TIMEOUT;
654 /** \ingroup msg_gos_functions
655 * \brief This function is called by a sender and permit to wait for each communication
657 * \param comm a vector of communication
658 * \param nb_elem is the size of the comm vector
659 * \param timeout for each call of MSG_comm_wait
661 void MSG_comm_waitall(msg_comm_t * comm, int nb_elem, double timeout)
664 for (i = 0; i < nb_elem; i++) {
665 MSG_comm_wait(comm[i], timeout);
669 /** \ingroup msg_gos_functions
670 * \brief This function waits for the first communication finished in a list.
671 * \param comms a vector of communications
672 * \return the position of the first finished communication
673 * (but it may have failed, use MSG_comm_get_status() to know its status)
675 int MSG_comm_waitany(xbt_dynar_t comms)
678 int finished_index = -1;
680 /* create the equivalent dynar with SIMIX objects */
681 xbt_dynar_t s_comms = xbt_dynar_new(sizeof(smx_action_t), NULL);
684 xbt_dynar_foreach(comms, cursor, comm) {
685 xbt_dynar_push(s_comms, &comm->s_comm);
688 MSG_error_t status = MSG_OK;
690 finished_index = SIMIX_req_comm_waitany(s_comms);
693 switch (e.category) {
696 finished_index = e.value;
697 status = MSG_HOST_FAILURE;
701 finished_index = e.value;
702 status = MSG_TRANSFER_FAILURE;
706 finished_index = e.value;
707 status = MSG_TIMEOUT;
716 xbt_assert0(finished_index != -1, "WaitAny returned -1");
717 xbt_dynar_free(&s_comms);
719 comm = xbt_dynar_get_as(comms, finished_index, msg_comm_t);
720 /* the communication is finished */
721 comm->status = status;
723 return finished_index;
727 * \ingroup msg_gos_functions
728 * \brief Returns the error (if any) that occured during a finished communication.
729 * \param comm a finished communication
730 * \return the status of the communication, or MSG_OK if no error occured
731 * during the communication
733 MSG_error_t MSG_comm_get_status(msg_comm_t comm) {
738 m_task_t MSG_comm_get_task(msg_comm_t comm)
740 xbt_assert0(comm, "Invalid parameter");
742 return comm->task_received ? *comm->task_received : comm->task_sent;
745 /** \ingroup msg_gos_functions
746 * \brief Put a task on a channel of an host and waits for the end of the
749 * This function is used for describing the behavior of an agent. It
750 * takes three parameter.
751 * \param task a #m_task_t to send on another location. This task
752 will not be usable anymore when the function will return. There is
753 no automatic task duplication and you have to save your parameters
754 before calling this function. Tasks are unique and once it has been
755 sent to another location, you should not access it anymore. You do
756 not need to call MSG_task_destroy() but to avoid using, as an
757 effect of inattention, this task anymore, you definitely should
758 renitialize it with #MSG_TASK_UNINITIALIZED. Note that this task
759 can be transfered iff it has been correctly created with
761 * \param dest the destination of the message
762 * \param channel the channel on which the agent should put this
763 task. This value has to be >=0 and < than the maximal number of
764 channels fixed with MSG_set_channel_number().
765 * \return #MSG_FATAL if \a task is not properly initialized and
766 * #MSG_OK otherwise. Returns #MSG_HOST_FAILURE if the host on which
767 * this function was called was shut down. Returns
768 * #MSG_TRANSFER_FAILURE if the transfer could not be properly done
769 * (network failure, dest failure)
771 MSG_error_t MSG_task_put(m_task_t task, m_host_t dest, m_channel_t channel)
773 return MSG_task_put_with_timeout(task, dest, channel, -1.0);
776 /** \ingroup msg_gos_functions
777 * \brief Does exactly the same as MSG_task_put but with a bounded transmition
783 MSG_task_put_bounded(m_task_t task, m_host_t dest, m_channel_t channel,
786 task->simdata->rate = maxrate;
787 return MSG_task_put(task, dest, channel);
790 /** \ingroup msg_gos_functions \brief Put a task on a channel of an
791 * host (with a timeout on the waiting of the destination host) and
792 * waits for the end of the transmission.
794 * This function is used for describing the behavior of an agent. It
795 * takes four parameter.
796 * \param task a #m_task_t to send on another location. This task
797 will not be usable anymore when the function will return. There is
798 no automatic task duplication and you have to save your parameters
799 before calling this function. Tasks are unique and once it has been
800 sent to another location, you should not access it anymore. You do
801 not need to call MSG_task_destroy() but to avoid using, as an
802 effect of inattention, this task anymore, you definitely should
803 renitialize it with #MSG_TASK_UNINITIALIZED. Note that this task
804 can be transfered iff it has been correctly created with
806 * \param dest the destination of the message
807 * \param channel the channel on which the agent should put this
808 task. This value has to be >=0 and < than the maximal number of
809 channels fixed with MSG_set_channel_number().
810 * \param timeout the maximum time to wait for a task before giving
811 up. In such a case, #MSG_TRANSFER_FAILURE will be returned, \a task
813 * \return #MSG_FATAL if \a task is not properly initialized and
814 #MSG_OK otherwise. Returns #MSG_HOST_FAILURE if the host on which
815 this function was called was shut down. Returns
816 #MSG_TRANSFER_FAILURE if the transfer could not be properly done
817 (network failure, dest failure, timeout...)
820 MSG_task_put_with_timeout(m_task_t task, m_host_t dest,
821 m_channel_t channel, double timeout)
823 xbt_assert1((channel >= 0)
824 && (channel < msg_global->max_channel), "Invalid channel %d",
827 XBT_DEBUG("MSG_task_put_with_timout: Trying to send a task to '%s'", dest->name);
829 MSG_mailbox_put_with_timeout(MSG_mailbox_get_by_channel
830 (dest, channel), task, timeout);
833 MSG_error_t MSG_task_send(m_task_t task, const char *alias)
835 XBT_DEBUG("MSG_task_send: Trying to send a message on mailbox '%s'", alias);
836 return MSG_task_send_with_timeout(task, alias, -1);
841 MSG_task_send_bounded(m_task_t task, const char *alias, double maxrate)
843 task->simdata->rate = maxrate;
844 return MSG_task_send(task, alias);
849 MSG_task_send_with_timeout(m_task_t task, const char *alias,
852 return MSG_mailbox_put_with_timeout(MSG_mailbox_get_by_alias(alias),
856 int MSG_task_listen(const char *alias)
860 return !MSG_mailbox_is_empty(MSG_mailbox_get_by_alias(alias));
863 /** \ingroup msg_gos_functions
864 * \brief Test whether there is a pending communication on a channel.
866 * It takes one parameter.
867 * \param channel the channel on which the agent should be
868 listening. This value has to be >=0 and < than the maximal
869 number of channels fixed with MSG_set_channel_number().
870 * \return 1 if there is a pending communication and 0 otherwise
872 int MSG_task_Iprobe(m_channel_t channel)
874 xbt_assert1((channel >= 0)
875 && (channel < msg_global->max_channel), "Invalid channel %d",
881 !MSG_mailbox_is_empty(MSG_mailbox_get_by_channel
882 (MSG_host_self(), channel));
885 /** \ingroup msg_gos_functions
887 * \brief Return the number of tasks waiting to be received on a \a
888 channel and sent by \a host.
890 * It takes two parameters.
891 * \param channel the channel on which the agent should be
892 listening. This value has to be >=0 and < than the maximal
893 number of channels fixed with MSG_set_channel_number().
894 * \param host the host that is to be watched.
895 * \return the number of tasks waiting to be received on \a channel
898 int MSG_task_probe_from_host(int channel, m_host_t host)
900 xbt_assert1((channel >= 0)
901 && (channel < msg_global->max_channel), "Invalid channel %d",
907 MSG_mailbox_get_count_host_waiting_tasks(MSG_mailbox_get_by_channel
908 (MSG_host_self(), channel),
913 int MSG_task_listen_from_host(const char *alias, m_host_t host)
918 MSG_mailbox_get_count_host_waiting_tasks(MSG_mailbox_get_by_alias
922 /** \ingroup msg_gos_functions
923 * \brief Test whether there is a pending communication on a channel, and who sent it.
925 * It takes one parameter.
926 * \param channel the channel on which the agent should be
927 listening. This value has to be >=0 and < than the maximal
928 number of channels fixed with MSG_set_channel_number().
929 * \return -1 if there is no pending communication and the PID of the process who sent it otherwise
931 int MSG_task_probe_from(m_channel_t channel)
937 xbt_assert1((channel >= 0)
938 && (channel < msg_global->max_channel), "Invalid channel %d",
943 MSG_mailbox_get_head(MSG_mailbox_get_by_channel
944 (MSG_host_self(), channel))))
947 return MSG_process_get_PID(task->simdata->sender);
950 int MSG_task_listen_from(const char *alias)
957 (task = MSG_mailbox_get_head(MSG_mailbox_get_by_alias(alias))))
960 return MSG_process_get_PID(task->simdata->sender);