Logo AND Algorithmique Numérique Distribuée

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