Logo AND Algorithmique Numérique Distribuée

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