Logo AND Algorithmique Numérique Distribuée

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