Logo AND Algorithmique Numérique Distribuée

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