Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge get-pid
[simgrid.git] / include / simgrid / s4u / actor.hpp
index 89a752e..9b38309 100644 (file)
@@ -132,7 +132,9 @@ private:
     Task(F&& code, Args&&... args) :
       code_(std::forward<F>(code)),
       args_(std::forward<Args>(args)...)
-    {}
+    {
+      done_.clear();
+    }
     void operator()()
     {
       if (done_.test_and_set())
@@ -140,7 +142,7 @@ private:
       simgrid::xbt::apply(std::move(code_), std::move(args_));
     }
   private:
-    std::atomic_flag done_ = ATOMIC_FLAG_INIT;
+    std::atomic_flag done_;
     F code_;
     std::tuple<Args...> args_;
   };
@@ -187,7 +189,7 @@ public:
   Actor(const char* name, s4u::Host *host, double killTime, std::function<void()> code);
 
   Actor(const char* name, s4u::Host *host, std::function<void()> code)
-    : Actor(name, host, -1.0d, std::move(code)) {};
+    : Actor(name, host, -1.0, std::move(code)) {};
 
   /** Create an actor using code
    *
@@ -204,6 +206,13 @@ public:
     Actor(name, host, wrap_task(std::move(code), std::move(args)...))
   {}
 
+  // Create actor from function name:
+
+  Actor(const char* name, s4u::Host *host, double killTime, const char* function, simgrid::xbt::args args);
+
+  Actor(const char* name, s4u::Host *host, const char* function, simgrid::xbt::args args) :
+    Actor(name, host, -1.0, function, std::move(args)) {}
+
   /** Retrieves the actor that have the given PID (or NULL if not existing) */
   //static Actor *byPid(int pid); not implemented
 
@@ -229,6 +238,7 @@ public:
   void kill();
 
   static void kill(int pid);
+  static Actor forPid(int pid);
   
   /**
    * Wait for the actor to finish.
@@ -240,6 +250,8 @@ public:
   /** Ask kindly to all actors to die. Only the issuer will survive. */
   static void killAll();
 
+  bool valid() const { return pimpl_ != nullptr; }
+
 private:
   smx_process_t pimpl_ = nullptr;
 };
@@ -265,6 +277,11 @@ namespace this_actor {
    * See \ref Comm for the full communication API (including non blocking communications).
   */
   XBT_PUBLIC(void) send(Mailbox &chan, void*payload, size_t simulatedSize);
+  
+  /**
+   * Return the PID of the current actor.
+   */
+  XBT_PUBLIC(int) getPid();
 
 };