Logo AND Algorithmique Numérique Distribuée

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