Logo AND Algorithmique Numérique Distribuée

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