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 m_process_t self = MSG_process_self();
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 DEBUG1("Computing on %s", MSG_process_self()->simdata->m_host->name);
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 self->simdata->waiting_action = simdata->compute;
75 comp_state = SIMIX_req_host_execution_wait(simdata->compute);
76 self->simdata->waiting_action = NULL;
80 DEBUG2("Execution task '%s' finished in state %d", task->name, comp_state);
81 if (comp_state == SIMIX_DONE) {
82 /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
83 simdata->computation_amount = 0.0;
85 simdata->compute = NULL;
87 TRACE_msg_task_execute_end(task);
90 } else if (SIMIX_req_host_get_state(SIMIX_host_self()) == 0) {
91 /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
93 simdata->compute = NULL;
95 TRACE_msg_task_execute_end(task);
97 MSG_RETURN(MSG_HOST_FAILURE);
99 /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
100 simdata->comm = NULL;
101 simdata->compute = NULL;
103 TRACE_msg_task_execute_end(task);
105 MSG_RETURN(MSG_TASK_CANCELLED);
109 /** \ingroup m_task_management
110 * \brief Creates a new #m_task_t (a parallel one....).
112 * A constructor for #m_task_t taking six arguments and returning the
113 corresponding object.
114 * \param name a name for the object. It is for user-level information
116 * \param host_nb the number of hosts implied in the parallel task.
117 * \param host_list an array of \p host_nb m_host_t.
118 * \param computation_amount an array of \p host_nb
119 doubles. computation_amount[i] is the total number of operations
120 that have to be performed on host_list[i].
121 * \param communication_amount an array of \p host_nb* \p host_nb doubles.
122 * \param data a pointer to any data may want to attach to the new
123 object. It is for user-level information and can be NULL. It can
124 be retrieved with the function \ref MSG_task_get_data.
126 * \return The new corresponding object.
129 MSG_parallel_task_create(const char *name, int host_nb,
130 const m_host_t * host_list,
131 double *computation_amount,
132 double *communication_amount, void *data)
135 simdata_task_t simdata = xbt_new0(s_simdata_task_t, 1);
136 m_task_t task = xbt_new0(s_m_task_t, 1);
137 task->simdata = simdata;
140 task->name = xbt_strdup(name);
144 simdata->computation_amount = 0;
145 simdata->message_size = 0;
146 simdata->compute = NULL;
147 simdata->comm = NULL;
148 simdata->rate = -1.0;
150 simdata->sender = NULL;
151 simdata->receiver = NULL;
152 simdata->source = NULL;
154 simdata->host_nb = host_nb;
155 simdata->host_list = xbt_new0(smx_host_t, host_nb);
156 simdata->comp_amount = computation_amount;
157 simdata->comm_amount = communication_amount;
159 for (i = 0; i < host_nb; i++)
160 simdata->host_list[i] = host_list[i]->simdata->smx_host;
165 MSG_error_t MSG_parallel_task_execute(m_task_t task)
167 simdata_task_t simdata = NULL;
168 e_smx_state_t comp_state;
169 m_process_t self = MSG_process_self();
172 simdata = task->simdata;
174 xbt_assert0((!simdata->compute)
175 && (task->simdata->isused == 0),
176 "This task is executed somewhere else. Go fix your code!");
178 xbt_assert0(simdata->host_nb,
179 "This is not a parallel task. Go to hell.");
181 DEBUG1("Parallel computing on %s", MSG_process_self()->simdata->m_host->name);
186 SIMIX_req_host_parallel_execute(task->name, simdata->host_nb,
188 simdata->comp_amount,
189 simdata->comm_amount, 1.0, -1.0);
190 DEBUG1("Parallel execution action created: %p", simdata->compute);
192 self->simdata->waiting_action = simdata->compute;
193 comp_state = SIMIX_req_host_execution_wait(simdata->compute);
194 self->simdata->waiting_action = NULL;
196 DEBUG2("Finished waiting for execution of action %p, state = %d", simdata->compute, comp_state);
200 if (comp_state == SIMIX_DONE) {
201 /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
202 simdata->computation_amount = 0.0;
203 simdata->comm = NULL;
204 simdata->compute = NULL;
206 } else if (SIMIX_req_host_get_state(SIMIX_host_self()) == 0) {
207 /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
208 simdata->comm = NULL;
209 simdata->compute = NULL;
210 MSG_RETURN(MSG_HOST_FAILURE);
212 /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
213 simdata->comm = NULL;
214 simdata->compute = NULL;
215 MSG_RETURN(MSG_TASK_CANCELLED);
220 /** \ingroup msg_gos_functions
221 * \brief Sleep for the specified number of seconds
223 * Makes the current process sleep until \a time seconds have elapsed.
225 * \param nb_sec a number of second
227 MSG_error_t MSG_process_sleep(double nb_sec)
230 /*m_process_t proc = MSG_process_self();*/
233 TRACE_msg_process_sleep_in(MSG_process_self());
236 /* create action to sleep */
237 state = SIMIX_req_process_sleep(nb_sec);
239 /*proc->simdata->waiting_action = act_sleep;
241 FIXME: check if not setting the waiting_action breaks something on msg
243 proc->simdata->waiting_action = NULL;*/
245 if (state == SIMIX_DONE) {
247 TRACE_msg_process_sleep_out(MSG_process_self());
252 TRACE_msg_process_sleep_out(MSG_process_self());
254 MSG_RETURN(MSG_HOST_FAILURE);
258 /** \ingroup msg_gos_functions
259 * \brief Listen on \a channel and waits for receiving a task from \a host.
261 * It takes three parameters.
262 * \param task a memory location for storing a #m_task_t. It will
263 hold a task when this function will return. Thus \a task should not
264 be equal to \c NULL and \a *task should be equal to \c NULL. If one of
265 those two condition does not hold, there will be a warning message.
266 * \param channel the channel on which the agent should be
267 listening. This value has to be >=0 and < than the maximal
268 number of channels fixed with MSG_set_channel_number().
269 * \param host the host that is to be watched.
270 * \return #MSG_FATAL if \a task is equal to \c NULL, #MSG_WARNING
271 if \a *task is not equal to \c NULL, and #MSG_OK otherwise.
274 MSG_task_get_from_host(m_task_t * task, m_channel_t channel, m_host_t host)
276 return MSG_task_get_ext(task, channel, -1, host);
279 /** \ingroup msg_gos_functions
280 * \brief Listen on a channel and wait for receiving a task.
282 * It takes two parameters.
283 * \param task a memory location for storing a #m_task_t. It will
284 hold a task when this function will return. Thus \a task should not
285 be equal to \c NULL and \a *task should be equal to \c NULL. If one of
286 those two condition does not hold, there will be a warning message.
287 * \param channel the channel on which the agent should be
288 listening. This value has to be >=0 and < than the maximal
289 number of channels fixed with MSG_set_channel_number().
290 * \return #MSG_FATAL if \a task is equal to \c NULL, #MSG_WARNING
291 * if \a *task is not equal to \c NULL, and #MSG_OK otherwise.
293 MSG_error_t MSG_task_get(m_task_t * task, m_channel_t channel)
295 return MSG_task_get_with_timeout(task, channel, -1);
298 /** \ingroup msg_gos_functions
299 * \brief Listen on a channel and wait for receiving a task with a timeout.
301 * It takes three parameters.
302 * \param task a memory location for storing a #m_task_t. It will
303 hold a task when this function will return. Thus \a task should not
304 be equal to \c NULL and \a *task should be equal to \c NULL. If one of
305 those two condition does not hold, there will be a warning message.
306 * \param channel the channel on which the agent should be
307 listening. This value has to be >=0 and < than the maximal
308 number of channels fixed with MSG_set_channel_number().
309 * \param max_duration the maximum time to wait for a task before giving
310 up. In such a case, #MSG_TRANSFER_FAILURE will be returned, \a task
311 will not be modified and will still be
312 equal to \c NULL when returning.
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_with_timeout(m_task_t * task, m_channel_t channel,
320 return MSG_task_get_ext(task, channel, max_duration, NULL);
323 /** \defgroup msg_gos_functions MSG Operating System Functions
324 * \brief This section describes the functions that can be used
325 * by an agent for handling some task.
329 MSG_task_get_ext(m_task_t * task, m_channel_t channel, double timeout,
332 xbt_assert1((channel >= 0)
333 && (channel < msg_global->max_channel), "Invalid channel %d",
337 MSG_mailbox_get_task_ext(MSG_mailbox_get_by_channel
338 (MSG_host_self(), channel), task, host,
343 MSG_task_receive_from_host(m_task_t * task, const char *alias,
346 return MSG_task_receive_ext(task, alias, -1, host);
349 MSG_error_t MSG_task_receive(m_task_t * task, const char *alias)
351 return MSG_task_receive_with_timeout(task, alias, -1);
355 MSG_task_receive_with_timeout(m_task_t * task, const char *alias,
358 return MSG_task_receive_ext(task, alias, timeout, NULL);
362 MSG_task_receive_ext(m_task_t * task, const char *alias, double timeout,
366 ("MSG_task_receive_ext: Trying to receive a message on mailbox '%s'",
368 return MSG_mailbox_get_task_ext(MSG_mailbox_get_by_alias(alias), task,
372 /** \ingroup msg_gos_functions
373 * \brief Sends a task on a mailbox.
375 * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test()
376 * to end the communication.
378 * \param task a #m_task_t to send on another location.
379 * \param alias name of the mailbox to sent the task to
380 * \return the msg_comm_t communication created
382 msg_comm_t MSG_task_isend(m_task_t task, const char *alias)
384 simdata_task_t t_simdata = NULL;
385 m_process_t process = MSG_process_self();
386 msg_mailbox_t mailbox = MSG_mailbox_get_by_alias(alias);
390 /* FIXME: these functions are not traceable */
392 /* Prepare the task to send */
393 t_simdata = task->simdata;
394 t_simdata->sender = process;
395 t_simdata->source = MSG_host_self();
397 xbt_assert0(t_simdata->isused == 0,
398 "This task is still being used somewhere else. You cannot send it now. Go fix your code!");
400 t_simdata->isused = 1;
401 msg_global->sent_msg++;
403 /* Send it by calling SIMIX network layer */
404 msg_comm_t comm = xbt_new0(s_msg_comm_t, 1);
405 comm->task_sent = task;
406 comm->task_received = NULL;
407 comm->status = MSG_OK;
409 SIMIX_req_comm_isend(mailbox, t_simdata->message_size,
410 t_simdata->rate, task, sizeof(void *), NULL, NULL);
411 t_simdata->comm = comm->s_comm; /* FIXME: is the field t_simdata->comm still useful? */
416 /** \ingroup msg_gos_functions
417 * \brief Starts listening for receiving a task from an asynchronous communication.
419 * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test()
420 * to end the communication.
422 * \param task a memory location for storing a #m_task_t.
423 * \param name of the mailbox to receive the task on
424 * \return the msg_comm_t communication created
426 msg_comm_t MSG_task_irecv(m_task_t *task, const char *alias)
428 smx_rdv_t rdv = MSG_mailbox_get_by_alias(alias);
432 /* FIXME: these functions are not tracable */
435 xbt_assert0(task, "Null pointer for the task storage");
439 ("MSG_task_get() was asked to write in a non empty task struct.");
441 /* Try to receive it by calling SIMIX network layer */
442 msg_comm_t comm = xbt_new0(s_msg_comm_t, 1);
443 comm->task_sent = NULL;
444 comm->task_received = task;
445 comm->status = MSG_OK;
446 comm->s_comm = SIMIX_req_comm_irecv(rdv, task, NULL, NULL, NULL);
451 /** \ingroup msg_gos_functions
452 * \brief Checks whether a communication is done, and if yes, finalizes it.
453 * \param comm the communication to test
454 * \return TRUE if the communication is finished
455 * (but it may have failed, use MSG_comm_get_status() to know its status)
456 * or FALSE if the communication is not finished yet
457 * If the status is FALSE, don't forget to use MSG_process_sleep() after the test.
459 int MSG_comm_test(msg_comm_t comm)
464 finished = SIMIX_req_comm_test(comm->s_comm);
467 switch (e.category) {
470 comm->status = MSG_HOST_FAILURE;
475 comm->status = MSG_TRANSFER_FAILURE;
480 comm->status = MSG_TIMEOUT;
493 /** \ingroup msg_gos_functions
494 * \brief This function checks if a communication is finished.
495 * \param comms a vector of communications
496 * \return the position of the finished communication if any
497 * (but it may have failed, use MSG_comm_get_status() to know its status),
498 * or -1 if none is finished
500 int MSG_comm_testany(xbt_dynar_t comms)
503 int finished_index = -1;
505 /* create the equivalent dynar with SIMIX objects */
506 xbt_dynar_t s_comms = xbt_dynar_new(sizeof(smx_action_t), NULL);
509 xbt_dynar_foreach(comms, cursor, comm) {
510 xbt_dynar_push(s_comms, &comm->s_comm);
513 MSG_error_t status = MSG_OK;
515 finished_index = SIMIX_req_comm_testany(s_comms);
518 switch (e.category) {
521 finished_index = e.value;
522 status = MSG_HOST_FAILURE;
526 finished_index = e.value;
527 status = MSG_TRANSFER_FAILURE;
531 finished_index = e.value;
532 status = MSG_TIMEOUT;
540 xbt_dynar_free(&s_comms);
542 if (finished_index != -1) {
543 comm = xbt_dynar_get_as(comms, finished_index, msg_comm_t);
544 /* the communication is finished */
545 comm->status = status;
548 return finished_index;
551 /** \ingroup msg_gos_functions
552 * \brief Destroys a communication.
553 * \param comm the communication to destroy.
555 void MSG_comm_destroy(msg_comm_t comm)
557 if (comm->task_received != NULL
558 && *comm->task_received != NULL
559 && MSG_comm_get_status(comm) == MSG_OK) {
560 (*comm->task_received)->simdata->isused = 0;
563 /* FIXME auto-destroy comms from SIMIX to avoid this request */
564 SIMIX_req_comm_destroy(comm->s_comm);
568 /** \ingroup msg_gos_functions
569 * \brief Wait for the completion of a communication.
571 * It takes two parameters.
572 * \param comm the communication to wait.
573 * \param timeout Wait until the communication terminates or the timeout occurs
574 * \return MSG_error_t
576 MSG_error_t MSG_comm_wait(msg_comm_t comm, double timeout)
580 SIMIX_req_comm_wait(comm->s_comm, timeout);
582 if (comm->task_received != NULL) {
583 /* I am the receiver */
584 (*comm->task_received)->simdata->isused = 0;
587 /* FIXME: these functions are not traceable */
590 switch (e.category) {
592 comm->status = MSG_HOST_FAILURE;
595 comm->status = MSG_TRANSFER_FAILURE;
598 comm->status = MSG_TIMEOUT;
609 /** \ingroup msg_gos_functions
610 * \brief This function is called by a sender and permit to wait for each communication
612 * \param comm a vector of communication
613 * \param nb_elem is the size of the comm vector
614 * \param timeout for each call of MSG_comm_wait
616 void MSG_comm_waitall(msg_comm_t * comm, int nb_elem, double timeout)
619 for (i = 0; i < nb_elem; i++) {
620 MSG_comm_wait(comm[i], timeout);
624 /** \ingroup msg_gos_functions
625 * \brief This function waits for the first communication finished in a list.
626 * \param comms a vector of communications
627 * \return the position of the first finished communication
628 * (but it may have failed, use MSG_comm_get_status() to know its status)
630 int MSG_comm_waitany(xbt_dynar_t comms)
633 int finished_index = -1;
635 /* create the equivalent dynar with SIMIX objects */
636 xbt_dynar_t s_comms = xbt_dynar_new(sizeof(smx_action_t), NULL);
639 xbt_dynar_foreach(comms, cursor, comm) {
640 xbt_dynar_push(s_comms, &comm->s_comm);
643 MSG_error_t status = MSG_OK;
645 finished_index = SIMIX_req_comm_waitany(s_comms);
648 switch (e.category) {
651 finished_index = e.value;
652 status = MSG_HOST_FAILURE;
656 finished_index = e.value;
657 status = MSG_TRANSFER_FAILURE;
661 finished_index = e.value;
662 status = MSG_TIMEOUT;
671 xbt_assert0(finished_index != -1, "WaitAny returned -1");
672 xbt_dynar_free(&s_comms);
674 comm = xbt_dynar_get_as(comms, finished_index, msg_comm_t);
675 /* the communication is finished */
676 comm->status = status;
678 return finished_index;
682 * \ingroup msg_gos_functions
683 * \brief Returns the error (if any) that occured during a finished communication.
684 * \param comm a finished communication
685 * \return the status of the communication, or MSG_OK if no error occured
686 * during the communication
688 MSG_error_t MSG_comm_get_status(msg_comm_t comm) {
693 m_task_t MSG_comm_get_task(msg_comm_t comm)
695 xbt_assert0(comm, "Invalid parameter");
697 return comm->task_received ? *comm->task_received : comm->task_sent;
700 /** \ingroup msg_gos_functions
701 * \brief Put a task on a channel of an host and waits for the end of the
704 * This function is used for describing the behavior of an agent. It
705 * takes three parameter.
706 * \param task a #m_task_t to send on another location. This task
707 will not be usable anymore when the function will return. There is
708 no automatic task duplication and you have to save your parameters
709 before calling this function. Tasks are unique and once it has been
710 sent to another location, you should not access it anymore. You do
711 not need to call MSG_task_destroy() but to avoid using, as an
712 effect of inattention, this task anymore, you definitely should
713 renitialize it with #MSG_TASK_UNINITIALIZED. Note that this task
714 can be transfered iff it has been correctly created with
716 * \param dest the destination of the message
717 * \param channel the channel on which the agent should put this
718 task. This value has to be >=0 and < than the maximal number of
719 channels fixed with MSG_set_channel_number().
720 * \return #MSG_FATAL if \a task is not properly initialized and
721 * #MSG_OK otherwise. Returns #MSG_HOST_FAILURE if the host on which
722 * this function was called was shut down. Returns
723 * #MSG_TRANSFER_FAILURE if the transfer could not be properly done
724 * (network failure, dest failure)
726 MSG_error_t MSG_task_put(m_task_t task, m_host_t dest, m_channel_t channel)
728 return MSG_task_put_with_timeout(task, dest, channel, -1.0);
731 /** \ingroup msg_gos_functions
732 * \brief Does exactly the same as MSG_task_put but with a bounded transmition
738 MSG_task_put_bounded(m_task_t task, m_host_t dest, m_channel_t channel,
741 task->simdata->rate = maxrate;
742 return MSG_task_put(task, dest, channel);
745 /** \ingroup msg_gos_functions \brief Put a task on a channel of an
746 * host (with a timeout on the waiting of the destination host) and
747 * waits for the end of the transmission.
749 * This function is used for describing the behavior of an agent. It
750 * takes four 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 * \param timeout the maximum time to wait for a task before giving
766 up. In such a case, #MSG_TRANSFER_FAILURE will be returned, \a task
768 * \return #MSG_FATAL if \a task is not properly initialized and
769 #MSG_OK otherwise. Returns #MSG_HOST_FAILURE if the host on which
770 this function was called was shut down. Returns
771 #MSG_TRANSFER_FAILURE if the transfer could not be properly done
772 (network failure, dest failure, timeout...)
775 MSG_task_put_with_timeout(m_task_t task, m_host_t dest,
776 m_channel_t channel, double timeout)
778 xbt_assert1((channel >= 0)
779 && (channel < msg_global->max_channel), "Invalid channel %d",
782 DEBUG1("MSG_task_put_with_timout: Trying to send a task to '%s'", dest->name);
784 MSG_mailbox_put_with_timeout(MSG_mailbox_get_by_channel
785 (dest, channel), task, timeout);
788 MSG_error_t MSG_task_send(m_task_t task, const char *alias)
790 DEBUG1("MSG_task_send: Trying to send a message on mailbox '%s'", alias);
791 return MSG_task_send_with_timeout(task, alias, -1);
796 MSG_task_send_bounded(m_task_t task, const char *alias, double maxrate)
798 task->simdata->rate = maxrate;
799 return MSG_task_send(task, alias);
804 MSG_task_send_with_timeout(m_task_t task, const char *alias,
807 return MSG_mailbox_put_with_timeout(MSG_mailbox_get_by_alias(alias),
811 int MSG_task_listen(const char *alias)
815 return !MSG_mailbox_is_empty(MSG_mailbox_get_by_alias(alias));
818 /** \ingroup msg_gos_functions
819 * \brief Test whether there is a pending communication on a channel.
821 * It takes one parameter.
822 * \param channel the channel on which the agent should be
823 listening. This value has to be >=0 and < than the maximal
824 number of channels fixed with MSG_set_channel_number().
825 * \return 1 if there is a pending communication and 0 otherwise
827 int MSG_task_Iprobe(m_channel_t channel)
829 xbt_assert1((channel >= 0)
830 && (channel < msg_global->max_channel), "Invalid channel %d",
836 !MSG_mailbox_is_empty(MSG_mailbox_get_by_channel
837 (MSG_host_self(), channel));
840 /** \ingroup msg_gos_functions
842 * \brief Return the number of tasks waiting to be received on a \a
843 channel and sent by \a host.
845 * It takes two parameters.
846 * \param channel the channel on which the agent should be
847 listening. This value has to be >=0 and < than the maximal
848 number of channels fixed with MSG_set_channel_number().
849 * \param host the host that is to be watched.
850 * \return the number of tasks waiting to be received on \a channel
853 int MSG_task_probe_from_host(int channel, m_host_t host)
855 xbt_assert1((channel >= 0)
856 && (channel < msg_global->max_channel), "Invalid channel %d",
862 MSG_mailbox_get_count_host_waiting_tasks(MSG_mailbox_get_by_channel
863 (MSG_host_self(), channel),
868 int MSG_task_listen_from_host(const char *alias, m_host_t host)
873 MSG_mailbox_get_count_host_waiting_tasks(MSG_mailbox_get_by_alias
877 /** \ingroup msg_gos_functions
878 * \brief Test whether there is a pending communication on a channel, and who sent it.
880 * It takes one parameter.
881 * \param channel the channel on which the agent should be
882 listening. This value has to be >=0 and < than the maximal
883 number of channels fixed with MSG_set_channel_number().
884 * \return -1 if there is no pending communication and the PID of the process who sent it otherwise
886 int MSG_task_probe_from(m_channel_t channel)
892 xbt_assert1((channel >= 0)
893 && (channel < msg_global->max_channel), "Invalid channel %d",
898 MSG_mailbox_get_head(MSG_mailbox_get_by_channel
899 (MSG_host_self(), channel))))
902 return MSG_process_get_PID(task->simdata->sender);
905 int MSG_task_listen_from(const char *alias)
912 (task = MSG_mailbox_get_head(MSG_mailbox_get_by_alias(alias))))
915 return MSG_process_get_PID(task->simdata->sender);