Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
getters don't have to be simcalls
[simgrid.git] / src / s4u / s4u_Actor.cpp
index fe048a5..b5bbadd 100644 (file)
@@ -5,11 +5,14 @@
 
 #include "simgrid/Exception.hpp"
 #include "simgrid/actor.h"
+#include "simgrid/modelchecker.h"
 #include "simgrid/s4u/Actor.hpp"
 #include "simgrid/s4u/Exec.hpp"
 #include "simgrid/s4u/Host.hpp"
 #include "simgrid/s4u/VirtualMachine.hpp"
+#include "src/include/mc/mc.h"
 #include "src/kernel/activity/ExecImpl.hpp"
+#include "src/mc/mc_replay.hpp"
 #include "src/simix/smx_private.hpp"
 #include "src/surf/HostImpl.hpp"
 
@@ -28,6 +31,7 @@ xbt::signal<void(Actor const&)> s4u::Actor::on_sleep;
 xbt::signal<void(Actor const&)> s4u::Actor::on_wake_up;
 xbt::signal<void(Actor const&)> s4u::Actor::on_migration_start;
 xbt::signal<void(Actor const&)> s4u::Actor::on_migration_end;
+xbt::signal<void(Actor const&)> s4u::Actor::on_termination;
 xbt::signal<void(Actor const&)> s4u::Actor::on_destruction;
 
 // ***** Actor creation *****
@@ -76,17 +80,32 @@ void intrusive_ptr_release(Actor* actor)
 {
   intrusive_ptr_release(actor->pimpl_);
 }
+int Actor::get_refcount()
+{
+  return pimpl_->get_refcount();
+}
 
 // ***** Actor methods *****
 
 void Actor::join()
 {
-  simcall_process_join(this->pimpl_, -1);
+  join(-1);
 }
 
 void Actor::join(double timeout)
 {
-  simcall_process_join(this->pimpl_, timeout);
+  auto issuer = SIMIX_process_self();
+  auto target = pimpl_;
+  simix::simcall_blocking([issuer, target, timeout] {
+    if (target->finished_) {
+      // The joined process is already finished, just wake up the issuer right away
+      issuer->simcall_answer();
+    } else {
+      smx_activity_t sync = issuer->join(target, timeout);
+      sync->simcalls_.push_back(&issuer->simcall);
+      issuer->waiting_synchro = sync;
+    }
+  });
 }
 
 void Actor::set_auto_restart(bool autorestart)
@@ -179,7 +198,7 @@ void Actor::resume()
 
 bool Actor::is_suspended()
 {
-  return simix::simcall([this] { return pimpl_->is_suspended(); });
+  return pimpl_->is_suspended();
 }
 
 void Actor::set_kill_time(double kill_time)
@@ -274,13 +293,25 @@ bool is_maestro()
 
 void sleep_for(double duration)
 {
-  if (duration > 0) {
-    kernel::actor::ActorImpl* actor = SIMIX_process_self();
-    Actor::on_sleep(*actor->ciface());
-
-    simcall_process_sleep(duration);
+  xbt_assert(std::isfinite(duration), "duration is not finite!");
 
-    Actor::on_wake_up(*actor->ciface());
+  if (duration > 0) {
+    kernel::actor::ActorImpl* issuer = SIMIX_process_self();
+    Actor::on_sleep(*issuer->ciface());
+
+    simix::simcall_blocking([issuer, duration]() {
+      if (MC_is_active() || MC_record_replay_is_active()) {
+        MC_process_clock_add(issuer, duration);
+        issuer->simcall_answer();
+        return;
+      }
+      smx_activity_t sync = issuer->sleep(duration);
+      sync->simcalls_.push_back(&issuer->simcall);
+      issuer->waiting_synchro = sync;
+
+    });
+
+    Actor::on_wake_up(*issuer->ciface());
   }
 }
 
@@ -289,11 +320,11 @@ void yield()
   simix::simcall([] { /* do nothing*/ });
 }
 
-XBT_PUBLIC void sleep_until(double timeout)
+XBT_PUBLIC void sleep_until(double wakeup_time)
 {
   double now = SIMIX_get_clock();
-  if (timeout > now)
-    sleep_for(timeout - now);
+  if (wakeup_time > now)
+    sleep_for(wakeup_time - now);
 }
 
 void execute(double flops)
@@ -442,11 +473,6 @@ void migrate(Host* new_host)
   SIMIX_process_self()->iface()->migrate(new_host);
 }
 
-void kill() /* deprecated */
-{
-  exit();
-}
-
 } // namespace this_actor
 } // namespace s4u
 } // namespace simgrid
@@ -673,3 +699,39 @@ void sg_actor_detach()
 {
   simgrid::kernel::actor::ActorImpl::detach();
 }
+
+aid_t sg_actor_self_get_pid()
+{
+  return simgrid::s4u::this_actor::get_pid();
+}
+
+aid_t sg_actor_self_get_ppid()
+{
+  return simgrid::s4u::this_actor::get_ppid();
+}
+
+const char* sg_actor_self_get_name()
+{
+  return simgrid::s4u::this_actor::get_cname();
+}
+
+sg_actor_t sg_actor_self()
+{
+  return simgrid::s4u::Actor::self();
+}
+
+void sg_actor_self_execute(double flops)
+{
+  simgrid::s4u::this_actor::execute(flops);
+}
+
+/** @brief Take an extra reference on that actor to prevent it to be garbage-collected */
+void sg_actor_ref(sg_actor_t actor)
+{
+  intrusive_ptr_add_ref(actor);
+}
+/** @brief Release a reference on that actor so that it can get be garbage-collected */
+void sg_actor_unref(sg_actor_t actor)
+{
+  intrusive_ptr_release(actor);
+}