Logo AND Algorithmique Numérique Distribuée

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