Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Bounded receive
[simgrid.git] / src / msg / msg_gos.c
1 /* Copyright (c) 2004-2012. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "msg_private.h"
7 #include "msg_mailbox.h"
8 #include "mc/mc.h"
9 #include "xbt/log.h"
10 #include "xbt/sysdep.h"
11
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_gos, msg,
13                                 "Logging specific to MSG (gos)");
14
15 /** \ingroup msg_task_usage
16  * \brief Executes a task and waits for its termination.
17  *
18  * This function is used for describing the behavior of a process. It
19  * takes only one parameter.
20  * \param task a #msg_task_t to execute on the location on which the process is running.
21  * \return #MSG_OK if the task was successfully completed, #MSG_TASK_CANCELED
22  * or #MSG_HOST_FAILURE otherwise
23  */
24 msg_error_t MSG_task_execute(msg_task_t task)
25 {
26   return MSG_parallel_task_execute(task);
27 }
28
29 /** \ingroup msg_task_usage
30  * \brief Executes a parallel task and waits for its termination.
31  *
32  * \param task a #msg_task_t to execute on the location on which the process is running.
33  *
34  * \return #MSG_OK if the task was successfully completed, #MSG_TASK_CANCELED
35  * or #MSG_HOST_FAILURE otherwise
36  */
37 msg_error_t MSG_parallel_task_execute(msg_task_t task)
38 {
39   xbt_ex_t e;
40   simdata_task_t simdata = task->simdata;
41   msg_process_t self = SIMIX_process_self();
42   simdata_process_t p_simdata = SIMIX_process_self_get_data(self);
43   e_smx_state_t comp_state;
44   msg_error_t status = MSG_OK;
45
46 #ifdef HAVE_TRACING
47   TRACE_msg_task_execute_start(task);
48 #endif
49
50   xbt_assert((!simdata->compute) && (task->simdata->isused == 0),
51              "This task is executed somewhere else. Go fix your code! %d",
52              task->simdata->isused);
53
54   XBT_DEBUG("Computing on %s", MSG_process_get_name(MSG_process_self()));
55
56   if (simdata->computation_amount == 0 && !simdata->host_nb) {
57 #ifdef HAVE_TRACING
58     TRACE_msg_task_execute_end(task);
59 #endif
60     return MSG_OK;
61   }
62
63
64   TRY {
65
66     simdata->isused=1;
67
68     if (simdata->host_nb > 0) {
69       simdata->compute = simcall_host_parallel_execute(task->name,
70                                                        simdata->host_nb,
71                                                        simdata->host_list,
72                                                        simdata->comp_amount,
73                                                        simdata->comm_amount,
74                                                        1.0, -1.0);
75       XBT_DEBUG("Parallel execution action created: %p", simdata->compute);
76     } else {
77       simdata->compute = simcall_host_execute(task->name,
78                                               p_simdata->m_host,
79                                               simdata->computation_amount,
80                                               simdata->priority);
81
82     }
83 #ifdef HAVE_TRACING
84     simcall_set_category(simdata->compute, task->category);
85 #endif
86     p_simdata->waiting_action = simdata->compute;
87     comp_state = simcall_host_execution_wait(simdata->compute);
88
89     p_simdata->waiting_action = NULL;
90
91     simdata->isused=0;
92
93     XBT_DEBUG("Execution task '%s' finished in state %d",
94               task->name, (int)comp_state);
95   }
96   CATCH(e) {
97     switch (e.category) {
98     case cancel_error:
99       status = MSG_TASK_CANCELED;
100       break;
101     default:
102       RETHROW;
103     }
104     xbt_ex_free(e);
105   }
106   /* action ended, set comm and compute = NULL, the actions is already destroyed
107    * in the main function */
108   simdata->computation_amount = 0.0;
109   simdata->comm = NULL;
110   simdata->compute = NULL;
111 #ifdef HAVE_TRACING
112   TRACE_msg_task_execute_end(task);
113 #endif
114
115   MSG_RETURN(status);
116 }
117
118
119 /** \ingroup msg_task_usage
120  * \brief Sleep for the specified number of seconds
121  *
122  * Makes the current process sleep until \a time seconds have elapsed.
123  *
124  * \param nb_sec a number of second
125  */
126 msg_error_t MSG_process_sleep(double nb_sec)
127 {
128   msg_error_t status = MSG_OK;
129   /*msg_process_t proc = MSG_process_self();*/
130
131 #ifdef HAVE_TRACING
132   TRACE_msg_process_sleep_in(MSG_process_self());
133 #endif
134
135   /* create action to sleep */
136
137   /*proc->simdata->waiting_action = act_sleep;
138
139   FIXME: check if not setting the waiting_action breaks something on msg
140   
141   proc->simdata->waiting_action = NULL;*/
142
143   simcall_process_sleep(nb_sec);
144
145   #ifdef HAVE_TRACING
146     TRACE_msg_process_sleep_out(MSG_process_self());
147   #endif
148   MSG_RETURN(status);
149 }
150
151 /** \ingroup msg_task_usage
152  * \brief Deprecated function that used to receive a task from a mailbox from a specific host.
153  *
154  * Sorry, this function is not supported anymore. That wouldn't be
155  * impossible to reimplement it, but we are lacking the time to do so ourselves.
156  * If you need this functionality, you can either:
157  *
158  *  - implement the buffering mechanism on the user-level by queuing all messages
159  *    received in the mailbox that do not match your expectation
160  *  - change your application logic to leverage the mailboxes features. For example,
161  *    if you have A receiving messages from B and C, you could have A waiting on
162  *    mailbox "A" most of the time, but on "A#B" when it's waiting for specific
163  *    messages from B and "A#C" when waiting for messages from C. You could even get A
164  *    sometime waiting on all these mailboxes using @ref MSG_comm_waitany. You can find
165  *    an example of use of this function in the @ref MSG_examples section.
166  *  - Provide a proper patch to implement this functionality back in MSG. That wouldn't be
167  *    very difficult actually. Check the function @ref MSG_mailbox_get_task_ext. During its call to
168  *    simcall_comm_recv(), the 5th argument, match_fun, is NULL. Create a function that filters
169  *    messages according to the host (that you will pass as sixth argument to simcall_comm_recv()
170  *    and that your filtering function will receive as first parameter, and then, the filter could
171  *    simply compare the host names, for example. After sufficient testing, provide an example that
172  *    we could add to the distribution, and your first contribution to SimGrid is ready. Thanks in advance.
173  *
174  * \param task a memory location for storing a #msg_task_t.
175  * \param alias name of the mailbox to receive the task from
176  * \param host a #msg_host_t host from where the task was sent
177  *
178  * \return Returns
179  * #MSG_OK if the task was successfully received,
180  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
181  */
182 msg_error_t
183 MSG_task_receive_from_host(msg_task_t * task, const char *alias,
184                            msg_host_t host)
185 {
186   return MSG_task_receive_ext(task, alias, -1, host);
187 }
188
189 /** msg_task_usage
190  *\brief Deprecated function that used to receive a task from a mailbox from a specific host
191  *\brief at a given rate
192  *
193  * \param task a memory location for storing a #msg_task_t.
194  * \param alias name of the mailbox to receive the task from
195  * \param host a #msg_host_t host from where the task was sent
196  * \param rate limit the reception to rate bandwidth
197  *
198  * \return Returns
199  * #MSG_OK if the task was successfully received,
200  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
201  */
202 msg_error_t
203 MSG_task_receive_from_host_bounded(msg_task_t * task, const char *alias,
204                            msg_host_t host, double rate)
205 {
206   return MSG_task_receive_ext_bounded(task, alias, -1, host, rate);
207 }
208
209 /** \ingroup msg_task_usage
210  * \brief Receives a task from a mailbox.
211  *
212  * This is a blocking function, the execution flow will be blocked
213  * until the task is received. See #MSG_task_irecv
214  * for receiving tasks asynchronously.
215  *
216  * \param task a memory location for storing a #msg_task_t.
217  * \param alias name of the mailbox to receive the task from
218  *
219  * \return Returns
220  * #MSG_OK if the task was successfully received,
221  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
222  */
223 msg_error_t MSG_task_receive(msg_task_t * task, const char *alias)
224 {
225   return MSG_task_receive_with_timeout(task, alias, -1);
226 }
227
228 /** \ingroup msg_task_usage
229  * \brief Receives a task from a mailbox at a given rate.
230  *
231  * \param task a memory location for storing a #msg_task_t.
232  * \param alias name of the mailbox to receive the task from
233  *  \param rate limit the reception to rate bandwidth
234  *
235  * \return Returns
236  * #MSG_OK if the task was successfully received,
237  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
238  */
239 msg_error_t MSG_task_receive_bounded(msg_task_t * task, const char *alias, double rate)
240 {
241   return MSG_task_receive_with_timeout_bounded(task, alias, -1, rate);
242 }
243
244 /** \ingroup msg_task_usage
245  * \brief Receives a task from a mailbox with a given timeout.
246  *
247  * This is a blocking function with a timeout, the execution flow will be blocked
248  * until the task is received or the timeout is achieved. See #MSG_task_irecv
249  * for receiving tasks asynchronously.  You can provide a -1 timeout
250  * to obtain an infinite timeout.
251  *
252  * \param task a memory location for storing a #msg_task_t.
253  * \param alias name of the mailbox to receive the task from
254  * \param timeout is the maximum wait time for completion (if -1, this call is the same as #MSG_task_receive)
255  *
256  * \return Returns
257  * #MSG_OK if the task was successfully received,
258  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
259  */
260 msg_error_t
261 MSG_task_receive_with_timeout(msg_task_t * task, const char *alias,
262                               double timeout)
263 {
264   return MSG_task_receive_ext(task, alias, timeout, NULL);
265 }
266
267 /** \ingroup msg_task_usage
268  * \brief Receives a task from a mailbox with a given timeout and at a given rate.
269  *
270  * \param task a memory location for storing a #msg_task_t.
271  * \param alias name of the mailbox to receive the task from
272  * \param timeout is the maximum wait time for completion (if -1, this call is the same as #MSG_task_receive)
273  *  \param rate limit the reception to rate bandwidth
274  *
275  * \return Returns
276  * #MSG_OK if the task was successfully received,
277  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
278  */
279 msg_error_t
280 MSG_task_receive_with_timeout_bounded(msg_task_t * task, const char *alias,
281                               double timeout,double rate)
282 {
283   return MSG_task_receive_ext_bounded(task, alias, timeout, NULL,rate);
284 }
285
286 /** \ingroup msg_task_usage
287  * \brief Receives a task from a mailbox from a specific host with a given timeout.
288  *
289  * This is a blocking function with a timeout, the execution flow will be blocked
290  * until the task is received or the timeout is achieved. See #MSG_task_irecv
291  * for receiving tasks asynchronously. You can provide a -1 timeout
292  * to obtain an infinite timeout.
293  *
294  * \param task a memory location for storing a #msg_task_t.
295  * \param alias name of the mailbox to receive the task from
296  * \param timeout is the maximum wait time for completion (provide -1 for no timeout)
297  * \param host a #msg_host_t host from where the task was sent
298  *
299  * \return Returns
300  * #MSG_OK if the task was successfully received,
301 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
302  */
303 msg_error_t
304 MSG_task_receive_ext(msg_task_t * task, const char *alias, double timeout,
305                      msg_host_t host)
306 {
307   XBT_DEBUG
308       ("MSG_task_receive_ext: Trying to receive a message on mailbox '%s'",
309        alias);
310   return MSG_mailbox_get_task_ext(MSG_mailbox_get_by_alias(alias), task,
311                                   host, timeout);
312 }
313
314 /** \ingroup msg_task_usage
315  * \brief Receives a task from a mailbox from a specific host with a given timeout
316  *  and at a given rate.
317  *
318  * \param task a memory location for storing a #msg_task_t.
319  * \param alias name of the mailbox to receive the task from
320  * \param timeout is the maximum wait time for completion (provide -1 for no timeout)
321  * \param host a #msg_host_t host from where the task was sent
322  * \param rate limit the reception to rate bandwidth
323  *
324  * \return Returns
325  * #MSG_OK if the task was successfully received,
326 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
327  */
328 msg_error_t
329 MSG_task_receive_ext_bounded(msg_task_t * task, const char *alias, double timeout,
330                      msg_host_t host, double rate)
331 {
332   XBT_DEBUG
333       ("MSG_task_receive_ext: Trying to receive a message on mailbox '%s'",
334        alias);
335   return MSG_mailbox_get_task_ext_bounded(MSG_mailbox_get_by_alias(alias), task,
336                                   host, timeout, rate);
337 }
338
339 /** \ingroup msg_task_usage
340  * \brief Sends a task on a mailbox.
341  *
342  * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test()
343  * to end the communication.
344  *
345  * \param task a #msg_task_t to send on another location.
346  * \param alias name of the mailbox to sent the task to
347  * \return the msg_comm_t communication created
348  */
349 msg_comm_t MSG_task_isend(msg_task_t task, const char *alias)
350 {
351   return MSG_task_isend_with_matching(task,alias,NULL,NULL);
352 }
353
354 /** \ingroup msg_task_usage
355  * \brief Sends a task on a mailbox with a maximum rate
356  *
357  * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test()
358  * to end the communication. The maxrate parameter allows the application
359  * to limit the bandwidth utilization of network links when sending the task.
360  *
361  * \param task a #msg_task_t to send on another location.
362  * \param alias name of the mailbox to sent the task to
363  * \param maxrate the maximum communication rate for sending this task .
364  * \return the msg_comm_t communication created
365  */
366 msg_comm_t MSG_task_isend_bounded(msg_task_t task, const char *alias, double maxrate)
367 {
368   task->simdata->rate = maxrate;
369   return MSG_task_isend_with_matching(task,alias,NULL,NULL);
370 }
371
372
373 /** \ingroup msg_task_usage
374  * \brief Sends a task on a mailbox, with support for matching requests
375  *
376  * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test()
377  * to end the communication.
378  *
379  * \param task a #msg_task_t to send on another location.
380  * \param alias name of the mailbox to sent the task to
381  * \param match_fun boolean function which parameters are:
382  *        - match_data_provided_here
383  *        - match_data_provided_by_other_side_if_any
384  *        - the_smx_action_describing_the_other_side
385  * \param match_data user provided data passed to match_fun
386  * \return the msg_comm_t communication created
387  */
388 XBT_INLINE msg_comm_t MSG_task_isend_with_matching(msg_task_t task, const char *alias,
389     int (*match_fun)(void*,void*, smx_action_t),
390     void *match_data)
391 {
392   simdata_task_t t_simdata = NULL;
393   msg_process_t process = MSG_process_self();
394   msg_mailbox_t mailbox = MSG_mailbox_get_by_alias(alias);
395
396 #ifdef HAVE_TRACING
397   int call_end = TRACE_msg_task_put_start(task);
398 #endif
399
400   /* Prepare the task to send */
401   t_simdata = task->simdata;
402   t_simdata->sender = process;
403   t_simdata->source = ((simdata_process_t) SIMIX_process_self_get_data(process))->m_host;
404
405   xbt_assert(t_simdata->isused == 0,
406               "This task is still being used somewhere else. You cannot send it now. Go fix your code!");
407
408   t_simdata->isused = 1;
409   t_simdata->comm = NULL;
410   msg_global->sent_msg++;
411
412   /* Send it by calling SIMIX network layer */
413   msg_comm_t comm = xbt_new0(s_msg_comm_t, 1);
414   comm->task_sent = task;
415   comm->task_received = NULL;
416   comm->status = MSG_OK;
417   comm->s_comm =
418     simcall_comm_isend(mailbox, t_simdata->message_size,
419                          t_simdata->rate, task, sizeof(void *), match_fun, NULL, match_data, 0);
420   t_simdata->comm = comm->s_comm; /* FIXME: is the field t_simdata->comm still useful? */
421 #ifdef HAVE_TRACING
422     if (TRACE_is_enabled()) {
423       simcall_set_category(comm->s_comm, task->category);
424     }
425 #endif
426
427 #ifdef HAVE_TRACING
428   if (call_end)
429     TRACE_msg_task_put_end();
430 #endif
431
432   return comm;
433 }
434
435 /** \ingroup msg_task_usage
436  * \brief Sends a task on a mailbox.
437  *
438  * This is a non blocking detached send function.
439  * Think of it as a best effort send. Keep in mind that the third parameter
440  * is only called if the communication fails. If the communication does work,
441  * it is responsibility of the receiver code to free anything related to
442  * the task, as usual. More details on this can be obtained on
443  * <a href="http://lists.gforge.inria.fr/pipermail/simgrid-user/2011-November/002649.html">this thread</a>
444  * in the SimGrid-user mailing list archive.
445  *
446  * \param task a #msg_task_t to send on another location.
447  * \param alias name of the mailbox to sent the task to
448  * \param cleanup a function to destroy the task if the
449  * communication fails, e.g. MSG_task_destroy
450  * (if NULL, no function will be called)
451  */
452 void MSG_task_dsend(msg_task_t task, const char *alias, void_f_pvoid_t cleanup)
453 {
454   simdata_task_t t_simdata = NULL;
455   msg_process_t process = MSG_process_self();
456   msg_mailbox_t mailbox = MSG_mailbox_get_by_alias(alias);
457
458   /* Prepare the task to send */
459   t_simdata = task->simdata;
460   t_simdata->sender = process;
461   t_simdata->source = ((simdata_process_t) SIMIX_process_self_get_data(process))->m_host;
462
463   xbt_assert(t_simdata->isused == 0,
464               "This task is still being used somewhere else. You cannot send it now. Go fix your code!");
465
466   t_simdata->isused = 1;
467   t_simdata->comm = NULL;
468   msg_global->sent_msg++;
469
470 #ifdef HAVE_TRACING
471   int call_end = TRACE_msg_task_put_start(task);
472 #endif
473
474   /* Send it by calling SIMIX network layer */
475   smx_action_t comm = simcall_comm_isend(mailbox, t_simdata->message_size,
476                        t_simdata->rate, task, sizeof(void *), NULL, cleanup, NULL, 1);
477   t_simdata->comm = comm;
478 #ifdef HAVE_TRACING
479     if (TRACE_is_enabled()) {
480       simcall_set_category(comm, task->category);
481     }
482 #endif
483
484 #ifdef HAVE_TRACING
485   if (call_end)
486     TRACE_msg_task_put_end();
487 #endif
488 }
489
490
491 /** \ingroup msg_task_usage
492  * \brief Sends a task on a mailbox with a maximal rate.
493  *
494  * This is a non blocking detached send function.
495  * Think of it as a best effort send. Keep in mind that the third parameter
496  * is only called if the communication fails. If the communication does work,
497  * it is responsibility of the receiver code to free anything related to
498  * the task, as usual. More details on this can be obtained on
499  * <a href="http://lists.gforge.inria.fr/pipermail/simgrid-user/2011-November/002649.html">this thread</a>
500  * in the SimGrid-user mailing list archive.
501  *
502  * \param task a #msg_task_t to send on another location.
503  * \param alias name of the mailbox to sent the task to
504  * \param cleanup a function to destroy the task if the
505  * communication fails, e.g. MSG_task_destroy
506  * (if NULL, no function will be called)
507  * \param maxrate the maximum communication rate for sending this task
508  * 
509  */
510 void MSG_task_dsend_bounded(msg_task_t task, const char *alias, void_f_pvoid_t cleanup, double maxrate)
511 {
512   task->simdata->rate = maxrate;
513   
514   simdata_task_t t_simdata = NULL;
515   msg_process_t process = MSG_process_self();
516   msg_mailbox_t mailbox = MSG_mailbox_get_by_alias(alias);
517
518   /* Prepare the task to send */
519   t_simdata = task->simdata;
520   t_simdata->sender = process;
521   t_simdata->source = ((simdata_process_t) SIMIX_process_self_get_data(process))->m_host;
522
523   xbt_assert(t_simdata->isused == 0,
524               "This task is still being used somewhere else. You cannot send it now. Go fix your code!");
525
526   t_simdata->isused = 1;
527   t_simdata->comm = NULL;
528   msg_global->sent_msg++;
529
530 #ifdef HAVE_TRACING
531   int call_end = TRACE_msg_task_put_start(task);
532 #endif
533
534   /* Send it by calling SIMIX network layer */
535   smx_action_t comm = simcall_comm_isend(mailbox, t_simdata->message_size,
536                        t_simdata->rate, task, sizeof(void *), NULL, cleanup, NULL, 1);
537   t_simdata->comm = comm;
538 #ifdef HAVE_TRACING
539     if (TRACE_is_enabled()) {
540       simcall_set_category(comm, task->category);
541     }
542 #endif
543
544 #ifdef HAVE_TRACING
545   if (call_end)
546     TRACE_msg_task_put_end();
547 #endif
548 }
549
550 /** \ingroup msg_task_usage
551  * \brief Starts listening for receiving a task from an asynchronous communication.
552  *
553  * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test()
554  * to end the communication.
555  * 
556  * \param task a memory location for storing a #msg_task_t. has to be valid until the end of the communication.
557  * \param name of the mailbox to receive the task on
558  * \return the msg_comm_t communication created
559  */
560 msg_comm_t MSG_task_irecv(msg_task_t *task, const char *name)
561 {
562   smx_rdv_t rdv = MSG_mailbox_get_by_alias(name);
563
564   /* FIXME: these functions are not traceable */
565
566   /* Sanity check */
567   xbt_assert(task, "Null pointer for the task storage");
568
569   if (*task)
570     XBT_CRITICAL
571         ("MSG_task_irecv() was asked to write in a non empty task struct.");
572
573   /* Try to receive it by calling SIMIX network layer */
574   msg_comm_t comm = xbt_new0(s_msg_comm_t, 1);
575   comm->task_sent = NULL;
576   comm->task_received = task;
577   comm->status = MSG_OK;
578   comm->s_comm = simcall_comm_irecv(rdv, task, NULL, NULL, NULL);
579
580   return comm;
581 }
582
583 /** \ingroup msg_task_usage
584  * \brief Starts listening for receiving a task from an asynchronous communication
585  * at a given rate.
586  *
587  * \param task a memory location for storing a #msg_task_t. has to be valid until the end of the communication.
588  * \param name of the mailbox to receive the task on
589  * \param rate limit the bandwidth to the given rate
590  * \return the msg_comm_t communication created
591  */
592 msg_comm_t MSG_task_irecv_bounded(msg_task_t *task, const char *name, double rate)
593 {
594
595
596   smx_rdv_t rdv = MSG_mailbox_get_by_alias(name);
597   simcall_comm_change_rate_first_action(rdv,rate);
598   /* FIXME: these functions are not traceable */
599
600   /* Sanity check */
601   xbt_assert(task, "Null pointer for the task storage");
602
603   if (*task)
604     XBT_CRITICAL
605         ("MSG_task_irecv() was asked to write in a non empty task struct.");
606
607   /* Try to receive it by calling SIMIX network layer */
608   msg_comm_t comm = xbt_new0(s_msg_comm_t, 1);
609   comm->task_sent = NULL;
610   comm->task_received = task;
611   comm->status = MSG_OK;
612   comm->s_comm = simcall_comm_irecv(rdv, task, NULL, NULL, NULL);
613
614   return comm;
615 }
616
617 /** \ingroup msg_task_usage
618  * \brief Checks whether a communication is done, and if yes, finalizes it.
619  * \param comm the communication to test
620  * \return TRUE if the communication is finished
621  * (but it may have failed, use MSG_comm_get_status() to know its status)
622  * or FALSE if the communication is not finished yet
623  * If the status is FALSE, don't forget to use MSG_process_sleep() after the test.
624  */
625 int MSG_comm_test(msg_comm_t comm)
626 {
627   xbt_ex_t e;
628   int finished = 0;
629
630   TRY {
631     finished = simcall_comm_test(comm->s_comm);
632
633     if (finished && comm->task_received != NULL) {
634       /* I am the receiver */
635       (*comm->task_received)->simdata->isused = 0;
636     }
637   }
638   CATCH(e) {
639     switch (e.category) {
640       case network_error:
641         comm->status = MSG_TRANSFER_FAILURE;
642         finished = 1;
643         break;
644
645       case timeout_error:
646         comm->status = MSG_TIMEOUT;
647         finished = 1;
648         break;
649
650       default:
651         RETHROW;
652     }
653     xbt_ex_free(e);
654   }
655
656   return finished;
657 }
658
659 /** \ingroup msg_task_usage
660  * \brief This function checks if a communication is finished.
661  * \param comms a vector of communications
662  * \return the position of the finished communication if any
663  * (but it may have failed, use MSG_comm_get_status() to know its status),
664  * or -1 if none is finished
665  */
666 int MSG_comm_testany(xbt_dynar_t comms)
667 {
668   xbt_ex_t e;
669   int finished_index = -1;
670
671   /* create the equivalent dynar with SIMIX objects */
672   xbt_dynar_t s_comms = xbt_dynar_new(sizeof(smx_action_t), NULL);
673   msg_comm_t comm;
674   unsigned int cursor;
675   xbt_dynar_foreach(comms, cursor, comm) {
676     xbt_dynar_push(s_comms, &comm->s_comm);
677   }
678
679   msg_error_t status = MSG_OK;
680   TRY {
681     finished_index = simcall_comm_testany(s_comms);
682   }
683   CATCH(e) {
684     switch (e.category) {
685       case network_error:
686         finished_index = e.value;
687         status = MSG_TRANSFER_FAILURE;
688         break;
689
690       case timeout_error:
691         finished_index = e.value;
692         status = MSG_TIMEOUT;
693         break;
694
695       default:
696         RETHROW;
697     }
698     xbt_ex_free(e);
699   }
700   xbt_dynar_free(&s_comms);
701
702   if (finished_index != -1) {
703     comm = xbt_dynar_get_as(comms, finished_index, msg_comm_t);
704     /* the communication is finished */
705     comm->status = status;
706
707     if (status == MSG_OK && comm->task_received != NULL) {
708       /* I am the receiver */
709       (*comm->task_received)->simdata->isused = 0;
710     }
711   }
712
713   return finished_index;
714 }
715
716 /** \ingroup msg_task_usage
717  * \brief Destroys a communication.
718  * \param comm the communication to destroy.
719  */
720 void MSG_comm_destroy(msg_comm_t comm)
721 {
722   xbt_free(comm);
723 }
724
725 /** \ingroup msg_task_usage
726  * \brief Wait for the completion of a communication.
727  *
728  * It takes two parameters.
729  * \param comm the communication to wait.
730  * \param timeout Wait until the communication terminates or the timeout 
731  * occurs. You can provide a -1 timeout to obtain an infinite timeout.
732  * \return msg_error_t
733  */
734 msg_error_t MSG_comm_wait(msg_comm_t comm, double timeout)
735 {
736   xbt_ex_t e;
737   TRY {
738     simcall_comm_wait(comm->s_comm, timeout);
739
740     if (comm->task_received != NULL) {
741       /* I am the receiver */
742       (*comm->task_received)->simdata->isused = 0;
743     }
744
745     /* FIXME: these functions are not traceable */
746   }
747   CATCH(e) {
748     switch (e.category) {
749     case network_error:
750       comm->status = MSG_TRANSFER_FAILURE;
751       break;
752     case timeout_error:
753       comm->status = MSG_TIMEOUT;
754       break;
755     default:
756       RETHROW;
757     }
758     xbt_ex_free(e);
759   }
760
761   return comm->status;
762 }
763
764 /** \ingroup msg_task_usage
765 * \brief This function is called by a sender and permit to wait for each communication
766 *
767 * \param comm a vector of communication
768 * \param nb_elem is the size of the comm vector
769 * \param timeout for each call of MSG_comm_wait
770 */
771 void MSG_comm_waitall(msg_comm_t * comm, int nb_elem, double timeout)
772 {
773   int i = 0;
774   for (i = 0; i < nb_elem; i++) {
775     MSG_comm_wait(comm[i], timeout);
776   }
777 }
778
779 /** \ingroup msg_task_usage
780  * \brief This function waits for the first communication finished in a list.
781  * \param comms a vector of communications
782  * \return the position of the first finished communication
783  * (but it may have failed, use MSG_comm_get_status() to know its status)
784  */
785 int MSG_comm_waitany(xbt_dynar_t comms)
786 {
787   xbt_ex_t e;
788   int finished_index = -1;
789
790   /* create the equivalent dynar with SIMIX objects */
791   xbt_dynar_t s_comms = xbt_dynar_new(sizeof(smx_action_t), NULL);
792   msg_comm_t comm;
793   unsigned int cursor;
794   xbt_dynar_foreach(comms, cursor, comm) {
795     xbt_dynar_push(s_comms, &comm->s_comm);
796   }
797
798   msg_error_t status = MSG_OK;
799   TRY {
800     finished_index = simcall_comm_waitany(s_comms);
801   }
802   CATCH(e) {
803     switch (e.category) {
804       case network_error:
805         finished_index = e.value;
806         status = MSG_TRANSFER_FAILURE;
807         break;
808
809       case timeout_error:
810         finished_index = e.value;
811         status = MSG_TIMEOUT;
812         break;
813
814       default:
815         RETHROW;
816     }
817     xbt_ex_free(e);
818   }
819
820   xbt_assert(finished_index != -1, "WaitAny returned -1");
821   xbt_dynar_free(&s_comms);
822
823   comm = xbt_dynar_get_as(comms, finished_index, msg_comm_t);
824   /* the communication is finished */
825   comm->status = status;
826
827   if (comm->task_received != NULL) {
828     /* I am the receiver */
829     (*comm->task_received)->simdata->isused = 0;
830   }
831
832   return finished_index;
833 }
834
835 /**
836  * \ingroup msg_task_usage
837  * \brief Returns the error (if any) that occured during a finished communication.
838  * \param comm a finished communication
839  * \return the status of the communication, or #MSG_OK if no error occured
840  * during the communication
841  */
842 msg_error_t MSG_comm_get_status(msg_comm_t comm) {
843
844   return comm->status;
845 }
846
847 /** \ingroup msg_task_usage
848  * \brief Get a task (#msg_task_t) from a communication
849  *
850  * \param comm the communication where to get the task
851  * \return the task from the communication
852  */
853 msg_task_t MSG_comm_get_task(msg_comm_t comm)
854 {
855   xbt_assert(comm, "Invalid parameter");
856
857   return comm->task_received ? *comm->task_received : comm->task_sent;
858 }
859
860 /**
861  * \brief This function is called by SIMIX in kernel mode to copy the data of a comm.
862  * \param comm the comm
863  * \param buff the data copied
864  * \param buff_size size of the buffer
865  */
866 void MSG_comm_copy_data_from_SIMIX(smx_action_t comm, void* buff, size_t buff_size) {
867
868   // copy the task
869   SIMIX_comm_copy_pointer_callback(comm, buff, buff_size);
870
871   // notify the user callback if any
872   if (msg_global->task_copy_callback) {
873     msg_task_t task = buff;
874     msg_global->task_copy_callback(task,
875         simcall_comm_get_src_proc(comm), simcall_comm_get_dst_proc(comm));
876   }
877 }
878
879 /** \ingroup msg_task_usage
880  * \brief Sends a task to a mailbox
881  *
882  * This is a blocking function, the execution flow will be blocked
883  * until the task is sent (and received in the other side if #MSG_task_receive is used).
884  * See #MSG_task_isend for sending tasks asynchronously.
885  *
886  * \param task the task to be sent
887  * \param alias the mailbox name to where the task is sent
888  *
889  * \return Returns #MSG_OK if the task was successfully sent,
890  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
891  */
892 msg_error_t MSG_task_send(msg_task_t task, const char *alias)
893 {
894   XBT_DEBUG("MSG_task_send: Trying to send a message on mailbox '%s'", alias);
895   return MSG_task_send_with_timeout(task, alias, -1);
896 }
897
898 /** \ingroup msg_task_usage
899  * \brief Sends a task to a mailbox with a maximum rate
900  *
901  * This is a blocking function, the execution flow will be blocked
902  * until the task is sent. The maxrate parameter allows the application
903  * to limit the bandwidth utilization of network links when sending the task.
904  *
905  * \param task the task to be sent
906  * \param alias the mailbox name to where the task is sent
907  * \param maxrate the maximum communication rate for sending this task
908  *
909  * \return Returns #MSG_OK if the task was successfully sent,
910  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
911  */
912 msg_error_t
913 MSG_task_send_bounded(msg_task_t task, const char *alias, double maxrate)
914 {
915   task->simdata->rate = maxrate;
916   return MSG_task_send(task, alias);
917 }
918
919 /** \ingroup msg_task_usage
920  * \brief Sends a task to a mailbox with a timeout
921  *
922  * This is a blocking function, the execution flow will be blocked
923  * until the task is sent or the timeout is achieved.
924  *
925  * \param task the task to be sent
926  * \param alias the mailbox name to where the task is sent
927  * \param timeout is the maximum wait time for completion (if -1, this call is the same as #MSG_task_send)
928  *
929  * \return Returns #MSG_OK if the task was successfully sent,
930  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
931  */
932 msg_error_t
933 MSG_task_send_with_timeout(msg_task_t task, const char *alias,
934                            double timeout)
935 {
936   return MSG_mailbox_put_with_timeout(MSG_mailbox_get_by_alias(alias),
937                                       task, timeout);
938 }
939
940 /** \ingroup msg_task_usage
941  * \brief Sends a task to a mailbox with a timeout and with a maximum rate
942  *
943  * This is a blocking function, the execution flow will be blocked
944  * until the task is sent or the timeout is achieved.
945  *
946  * \param task the task to be sent
947  * \param alias the mailbox name to where the task is sent
948  * \param timeout is the maximum wait time for completion (if -1, this call is the same as #MSG_task_send)
949  * \param maxrate the maximum communication rate for sending this task
950  *
951  * \return Returns #MSG_OK if the task was successfully sent,
952  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
953  */
954 msg_error_t
955 MSG_task_send_with_timeout_bounded(msg_task_t task, const char *alias,
956                            double timeout, double maxrate)
957 {
958   task->simdata->rate = maxrate;
959   return MSG_mailbox_put_with_timeout(MSG_mailbox_get_by_alias(alias),
960                                       task, timeout);
961 }
962
963 /** \ingroup msg_task_usage
964  * \brief Check if there is a communication going on in a mailbox.
965  *
966  * \param alias the name of the mailbox to be considered
967  *
968  * \return Returns 1 if there is a communication, 0 otherwise
969  */
970 int MSG_task_listen(const char *alias)
971 {
972   return !MSG_mailbox_is_empty(MSG_mailbox_get_by_alias(alias));
973 }
974
975 /** \ingroup msg_task_usage
976  * \brief Check the number of communication actions of a given host pending in a mailbox.
977  *
978  * \param alias the name of the mailbox to be considered
979  * \param host the host to check for communication
980  *
981  * \return Returns the number of pending communication actions of the host in the
982  * given mailbox, 0 if there is no pending communication actions.
983  *
984  */
985 int MSG_task_listen_from_host(const char *alias, msg_host_t host)
986 {
987   return
988       MSG_mailbox_get_count_host_waiting_tasks(MSG_mailbox_get_by_alias
989                                                (alias), host);
990 }
991
992 /** \ingroup msg_task_usage
993  * \brief Look if there is a communication on a mailbox and return the
994  * PID of the sender process.
995  *
996  * \param alias the name of the mailbox to be considered
997  *
998  * \return Returns the PID of sender process,
999  * -1 if there is no communication in the mailbox.
1000  */
1001 int MSG_task_listen_from(const char *alias)
1002 {
1003   msg_task_t task;
1004
1005   if (NULL ==
1006       (task = MSG_mailbox_get_head(MSG_mailbox_get_by_alias(alias))))
1007     return -1;
1008
1009   return MSG_process_get_PID(task->simdata->sender);
1010 }
1011
1012 /** \ingroup msg_task_usage
1013  * \brief Sets the tracing category of a task.
1014  *
1015  * This function should be called after the creation of
1016  * a MSG task, to define the category of that task. The
1017  * first parameter task must contain a task that was
1018  * created with the function #MSG_task_create. The second
1019  * parameter category must contain a category that was
1020  * previously declared with the function #TRACE_category
1021  * (or with #TRACE_category_with_color).
1022  *
1023  * See \ref tracing for details on how to trace
1024  * the (categorized) resource utilization.
1025  *
1026  * \param task the task that is going to be categorized
1027  * \param category the name of the category to be associated to the task
1028  *
1029  * \see MSG_task_get_category, TRACE_category, TRACE_category_with_color
1030  */
1031 void MSG_task_set_category (msg_task_t task, const char *category)
1032 {
1033 #ifdef HAVE_TRACING
1034   TRACE_msg_set_task_category (task, category);
1035 #endif
1036 }
1037
1038 /** \ingroup msg_task_usage
1039  *
1040  * \brief Gets the current tracing category of a task.
1041  *
1042  * \param task the task to be considered
1043  *
1044  * \see MSG_task_set_category
1045  *
1046  * \return Returns the name of the tracing category of the given task, NULL otherwise
1047  */
1048 const char *MSG_task_get_category (msg_task_t task)
1049 {
1050 #ifdef HAVE_TRACING
1051   return task->category;
1052 #else
1053   return NULL;
1054 #endif
1055 }
1056
1057 /**
1058  * \brief Returns the value of a given AS or router property
1059  *
1060  * \param asr the name of a router or AS
1061  * \param name a property name
1062  * \return value of a property (or NULL if property not set)
1063  */
1064 const char *MSG_as_router_get_property_value(const char* asr, const char *name)
1065 {
1066   return xbt_dict_get_or_null(MSG_as_router_get_properties(asr), name);
1067 }
1068
1069 /**
1070  * \brief Returns a xbt_dict_t consisting of the list of properties assigned to
1071  * a the AS or router
1072  *
1073  * \param asr the name of a router or AS
1074  * \return a dict containing the properties
1075  */
1076 xbt_dict_t MSG_as_router_get_properties(const char* asr)
1077 {
1078   return (simcall_asr_get_properties(asr));
1079 }
1080
1081 /**
1082  * \brief Change the value of a given AS or router
1083  *
1084  * \param asr the name of a router or AS
1085  * \param name a property name
1086  * \param value what to change the property to
1087  * \param free_ctn the freeing function to use to kill the value on need
1088  */
1089 void MSG_as_router_set_property_value(const char* asr, const char *name, char *value,void_f_pvoid_t free_ctn) {
1090   xbt_dict_set(MSG_as_router_get_properties(asr), name, value,free_ctn);
1091 }
1092
1093 #ifdef MSG_USE_DEPRECATED
1094 /** \ingroup msg_deprecated_functions
1095  *
1096  * \brief Return the last value returned by a MSG function (except
1097  * MSG_get_errno...).
1098  */
1099 msg_error_t MSG_get_errno(void)
1100 {
1101   return PROCESS_GET_ERRNO();
1102 }
1103
1104 /** \ingroup msg_deprecated_functions
1105  * \brief Put a task on a channel of an host and waits for the end of the
1106  * transmission.
1107  *
1108  * This function is used for describing the behavior of a process. It
1109  * takes three parameter.
1110  * \param task a #msg_task_t to send on another location. This task
1111  will not be usable anymore when the function will return. There is
1112  no automatic task duplication and you have to save your parameters
1113  before calling this function. Tasks are unique and once it has been
1114  sent to another location, you should not access it anymore. You do
1115  not need to call MSG_task_destroy() but to avoid using, as an
1116  effect of inattention, this task anymore, you definitely should
1117  renitialize it with #MSG_TASK_UNINITIALIZED. Note that this task
1118  can be transfered iff it has been correctly created with
1119  MSG_task_create().
1120  * \param dest the destination of the message
1121  * \param channel the channel on which the process should put this
1122  task. This value has to be >=0 and < than the maximal number of
1123  channels fixed with MSG_set_channel_number().
1124  * \return #MSG_HOST_FAILURE if the host on which
1125  * this function was called was shut down,
1126  * #MSG_TRANSFER_FAILURE if the transfer could not be properly done
1127  * (network failure, dest failure) or #MSG_OK if it succeeded.
1128  */
1129 msg_error_t MSG_task_put(msg_task_t task, msg_host_t dest, m_channel_t channel)
1130 {
1131   XBT_WARN("DEPRECATED! Now use MSG_task_send");
1132   return MSG_task_put_with_timeout(task, dest, channel, -1.0);
1133 }
1134
1135 /** \ingroup msg_deprecated_functions
1136  * \brief Does exactly the same as MSG_task_put but with a bounded transmition
1137  * rate.
1138  *
1139  * \sa MSG_task_put
1140  */
1141 msg_error_t
1142 MSG_task_put_bounded(msg_task_t task, msg_host_t dest, m_channel_t channel,
1143                      double maxrate)
1144 {
1145   XBT_WARN("DEPRECATED! Now use MSG_task_send_bounded");
1146   task->simdata->rate = maxrate;
1147   return MSG_task_put(task, dest, channel);
1148 }
1149
1150 /** \ingroup msg_deprecated_functions
1151  *
1152  * \brief Put a task on a channel of an
1153  * host (with a timeout on the waiting of the destination host) and
1154  * waits for the end of the transmission.
1155  *
1156  * This function is used for describing the behavior of a process. It
1157  * takes four parameter.
1158  * \param task a #msg_task_t to send on another location. This task
1159  will not be usable anymore when the function will return. There is
1160  no automatic task duplication and you have to save your parameters
1161  before calling this function. Tasks are unique and once it has been
1162  sent to another location, you should not access it anymore. You do
1163  not need to call MSG_task_destroy() but to avoid using, as an
1164  effect of inattention, this task anymore, you definitely should
1165  renitialize it with #MSG_TASK_UNINITIALIZED. Note that this task
1166  can be transfered iff it has been correctly created with
1167  MSG_task_create().
1168  * \param dest the destination of the message
1169  * \param channel the channel on which the process should put this
1170  task. This value has to be >=0 and < than the maximal number of
1171  channels fixed with MSG_set_channel_number().
1172  * \param timeout the maximum time to wait for a task before giving
1173  up. In such a case, #MSG_TRANSFER_FAILURE will be returned, \a task
1174  will not be modified
1175  * \return #MSG_HOST_FAILURE if the host on which
1176 this function was called was shut down,
1177 #MSG_TRANSFER_FAILURE if the transfer could not be properly done
1178 (network failure, dest failure, timeout...) or #MSG_OK if the communication succeeded.
1179  */
1180 msg_error_t
1181 MSG_task_put_with_timeout(msg_task_t task, msg_host_t dest,
1182                           m_channel_t channel, double timeout)
1183 {
1184   XBT_WARN("DEPRECATED! Now use MSG_task_send_with_timeout");
1185   xbt_assert((channel >= 0)
1186               && (channel < msg_global->max_channel), "Invalid channel %d",
1187               channel);
1188
1189   XBT_DEBUG("MSG_task_put_with_timout: Trying to send a task to '%s'", SIMIX_host_get_name(dest->smx_host));
1190   return
1191       MSG_mailbox_put_with_timeout(MSG_mailbox_get_by_channel
1192                                    (dest, channel), task, timeout);
1193 }
1194
1195 /** \ingroup msg_deprecated_functions
1196  * \brief Test whether there is a pending communication on a channel, and who sent it.
1197  *
1198  * It takes one parameter.
1199  * \param channel the channel on which the process should be
1200  listening. This value has to be >=0 and < than the maximal
1201  number of channels fixed with MSG_set_channel_number().
1202  * \return -1 if there is no pending communication and the PID of the process who sent it otherwise
1203  */
1204 int MSG_task_probe_from(m_channel_t channel)
1205 {
1206   XBT_WARN("DEPRECATED! Now use MSG_task_listen_from");
1207   msg_task_t task;
1208
1209   xbt_assert((channel >= 0)
1210               && (channel < msg_global->max_channel), "Invalid channel %d",
1211               channel);
1212
1213   if (NULL ==
1214       (task =
1215        MSG_mailbox_get_head(MSG_mailbox_get_by_channel
1216                             (MSG_host_self(), channel))))
1217     return -1;
1218
1219   return MSG_process_get_PID(task->simdata->sender);
1220 }
1221
1222 /** \ingroup msg_deprecated_functions
1223  * \brief Test whether there is a pending communication on a channel.
1224  *
1225  * It takes one parameter.
1226  * \param channel the channel on which the process should be
1227  listening. This value has to be >=0 and < than the maximal
1228  number of channels fixed with MSG_set_channel_number().
1229  * \return 1 if there is a pending communication and 0 otherwise
1230  */
1231 int MSG_task_Iprobe(m_channel_t channel)
1232 {
1233   XBT_WARN("DEPRECATED!");
1234   xbt_assert((channel >= 0)
1235               && (channel < msg_global->max_channel), "Invalid channel %d",
1236               channel);
1237
1238   return
1239       !MSG_mailbox_is_empty(MSG_mailbox_get_by_channel
1240                             (MSG_host_self(), channel));
1241 }
1242
1243 /** \ingroup msg_deprecated_functions
1244
1245  * \brief Return the number of tasks waiting to be received on a \a
1246  channel and sent by \a host.
1247  *
1248  * It takes two parameters.
1249  * \param channel the channel on which the process should be
1250  listening. This value has to be >=0 and < than the maximal
1251  number of channels fixed with MSG_set_channel_number().
1252  * \param host the host that is to be watched.
1253  * \return the number of tasks waiting to be received on \a channel
1254  and sent by \a host.
1255  */
1256 int MSG_task_probe_from_host(int channel, msg_host_t host)
1257 {
1258   XBT_WARN("DEPRECATED! Now use MSG_task_listen_from_host");
1259   xbt_assert((channel >= 0)
1260               && (channel < msg_global->max_channel), "Invalid channel %d",
1261               channel);
1262
1263   return
1264       MSG_mailbox_get_count_host_waiting_tasks(MSG_mailbox_get_by_channel
1265                                                (MSG_host_self(), channel),
1266                                                host);
1267
1268 }
1269
1270 /** \ingroup msg_deprecated_functions
1271  * \brief Listen on \a channel and waits for receiving a task from \a host.
1272  *
1273  * It takes three parameters.
1274  * \param task a memory location for storing a #msg_task_t. It will
1275  hold a task when this function will return. Thus \a task should not
1276  be equal to \c NULL and \a *task should be equal to \c NULL. If one of
1277  those two condition does not hold, there will be a warning message.
1278  * \param channel the channel on which the process should be
1279  listening. This value has to be >=0 and < than the maximal
1280  number of channels fixed with MSG_set_channel_number().
1281  * \param host the host that is to be watched.
1282  * \return a #msg_error_t indicating whether the operation was successful (#MSG_OK), or why it failed otherwise.
1283  */
1284 msg_error_t
1285 MSG_task_get_from_host(msg_task_t * task, m_channel_t channel, msg_host_t host)
1286 {
1287   XBT_WARN("DEPRECATED! Now use MSG_task_receive_from_host");
1288   return MSG_task_get_ext(task, channel, -1, host);
1289 }
1290
1291 /** \ingroup msg_deprecated_functions
1292  * \brief Listen on a channel and wait for receiving a task.
1293  *
1294  * It takes two parameters.
1295  * \param task a memory location for storing a #msg_task_t. It will
1296  hold a task when this function will return. Thus \a task should not
1297  be equal to \c NULL and \a *task should be equal to \c NULL. If one of
1298  those two condition does not hold, there will be a warning message.
1299  * \param channel the channel on which the process should be
1300  listening. This value has to be >=0 and < than the maximal
1301  number of channels fixed with MSG_set_channel_number().
1302  * \return a #msg_error_t indicating whether the operation was successful (#MSG_OK), or why it failed otherwise.
1303  */
1304 msg_error_t MSG_task_get(msg_task_t * task, m_channel_t channel)
1305 {
1306   XBT_WARN("DEPRECATED! Now use MSG_task_receive");
1307   return MSG_task_get_with_timeout(task, channel, -1);
1308 }
1309
1310 /** \ingroup msg_deprecated_functions
1311  * \brief Listen on a channel and wait for receiving a task with a timeout.
1312  *
1313  * It takes three parameters.
1314  * \param task a memory location for storing a #msg_task_t. It will
1315  hold a task when this function will return. Thus \a task should not
1316  be equal to \c NULL and \a *task should be equal to \c NULL. If one of
1317  those two condition does not hold, there will be a warning message.
1318  * \param channel the channel on which the process should be
1319  listening. This value has to be >=0 and < than the maximal
1320  number of channels fixed with MSG_set_channel_number().
1321  * \param max_duration the maximum time to wait for a task before giving
1322  up. In such a case, #MSG_TRANSFER_FAILURE will be returned, \a task
1323  will not be modified and will still be
1324  equal to \c NULL when returning.
1325  * \return a #msg_error_t indicating whether the operation was successful (#MSG_OK), or why it failed otherwise.
1326  */
1327 msg_error_t
1328 MSG_task_get_with_timeout(msg_task_t * task, m_channel_t channel,
1329                           double max_duration)
1330 {
1331   XBT_WARN("DEPRECATED! Now use MSG_task_receive_with_timeout");
1332   return MSG_task_get_ext(task, channel, max_duration, NULL);
1333 }
1334
1335 msg_error_t
1336 MSG_task_get_ext(msg_task_t * task, m_channel_t channel, double timeout,
1337                  msg_host_t host)
1338 {
1339   XBT_WARN("DEPRECATED! Now use MSG_task_receive_ext");
1340   xbt_assert((channel >= 0)
1341               && (channel < msg_global->max_channel), "Invalid channel %d",
1342               channel);
1343
1344   return
1345       MSG_mailbox_get_task_ext(MSG_mailbox_get_by_channel
1346                                (MSG_host_self(), channel), task, host,
1347                                timeout);
1348 }
1349
1350 #endif