Logo AND Algorithmique Numérique Distribuée

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