Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Define overridable Activity::complete() to be called on activity completion.
[simgrid.git] / include / simgrid / s4u / Activity.hpp
index 878ddbab5f2b37d35fa4928405cbc9b3ae94d76f..74ca77e2f673503cc1890a5093b067b6808765f3 100644 (file)
@@ -32,12 +32,23 @@ class XBT_PUBLIC Activity {
   friend Exec;
   friend Io;
 
+public:
+  // enum class State { ... }
+  XBT_DECLARE_ENUM_CLASS(State, INITED, STARTING, STARTED, CANCELED, FINISHED);
+
 protected:
   Activity()  = default;
   virtual ~Activity() = default;
 
   virtual bool is_assigned() const = 0;
 
+  virtual void complete(Activity::State state)
+  {
+    state_ = state;
+    if (state == State::FINISHED)
+      release_dependencies();
+  }
+
   void release_dependencies()
   {
     while (not successors_.empty()) {
@@ -74,7 +85,6 @@ protected:
       a->dependencies_.erase({this});
     } else
       throw std::invalid_argument("Dependency does not exist. Can not be removed.");
-
   }
 
 public:
@@ -92,9 +102,6 @@ public:
   Activity& operator=(Activity const&) = delete;
 #endif
 
-  // enum class State { ... }
-  XBT_DECLARE_ENUM_CLASS(State, INITED, STARTING, STARTED, CANCELED, FINISHED);
-
   /** Starts a previously created activity.
    *
    * This function is optional: you can call wait() even if you didn't call start()