Logo AND Algorithmique Numérique Distribuée

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