Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
adapt to the new simcall_comm_recv() prototype
[simgrid.git] / include / simgrid / s4u / async.hpp
1 /* Copyright (c) 2006-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 #ifndef SIMGRID_S4U_ASYNC_HPP
8 #define SIMGRID_S4U_ASYNC_HPP
9
10 namespace simgrid {
11 namespace s4u {
12
13 /* Forward declaration */
14 class Comm;
15
16 typedef enum {
17         inited, started, finished
18 } e_s4u_async_state_t;
19
20 /** @brief Asynchronous Actions
21  *
22  * This class is the ancestor of every asynchronous actions, that is, of actions that do take time in the simulated world.
23  */
24 class Async {
25         friend Comm;
26 protected:
27         Async();
28         virtual ~Async();
29         
30 private:
31         smx_synchro_t p_inferior = NULL;
32
33 private:
34         e_s4u_async_state_t p_state = inited;
35 public:
36         /** Starts a previously created async.
37          *
38          * This function is optional: you can call wait() even if you didn't call start()
39          */
40         virtual void start()=0;
41         /** Tests whether the given async is terminated yet */
42         //virtual bool test()=0;
43         /** Blocks until the async is terminated */
44         virtual void wait()=0;
45         /** Blocks until the async is terminated, or until the timeout is elapsed
46          *  Raises: timeout exception.*/
47         virtual void wait(double timeout)=0;
48         /** Cancel that async */
49         //virtual void cancel();
50         /** Retrieve the current state of the async */
51         e_s4u_async_state_t getState() {return p_state;}
52
53 private:
54         double p_remains = 0;
55 public:
56         /** Get the remaining amount of work that this Async entails. When it's 0, it's done. */
57         double getRemains();
58         /** Set the [remaining] amount of work that this Async will entail
59          *
60          * It is forbidden to change the amount of work once the Async is started */
61         void setRemains(double remains);
62
63 private:
64         void *p_userData = NULL;
65 public:
66         /** Put some user data onto the Async */
67         void setUserData(void *data) {p_userData=data;}
68         /** Retrieve the user data of the Async */
69         void *getUserData() { return p_userData; }
70 }; // class
71
72 }}; // Namespace simgrid::s4u
73
74 #endif /* SIMGRID_S4U_ASYNC_HPP */