]> AND Public Git Repository - simgrid.git/blobdiff - src/kernel/actor/ActorImpl.cpp
Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
migrate execute_tasks from simix::Global to kernel::EngineImpl
[simgrid.git] / src / kernel / actor / ActorImpl.cpp
index afcc7252318346135496a641e48a69590edd53c9..b0f00d2694fca68207fe337d3c3b42a3788311fe 100644 (file)
@@ -230,6 +230,9 @@ void ActorImpl::exit()
     activities_.remove(waiting_synchro_);
     waiting_synchro_ = nullptr;
   }
+  for (auto const& activity : activities_)
+    activity->cancel();
+  activities_.clear();
 
   // Forcefully kill the actor if its host is turned off. Not a HostFailureException because you should not survive that
   this->throw_exception(std::make_exception_ptr(ForcefulKillException(host_->is_on() ? "exited" : "host failed")));
@@ -272,7 +275,7 @@ void ActorImpl::set_kill_time(double kill_time)
   if (kill_time <= SIMIX_get_clock())
     return;
   XBT_DEBUG("Set kill time %f for actor %s@%s", kill_time, get_cname(), host_->get_cname());
-  kill_timer_ = simix::Timer::set(kill_time, [this] {
+  kill_timer_ = timer::Timer::set(kill_time, [this] {
     this->exit();
     kill_timer_ = nullptr;
   });
@@ -280,7 +283,7 @@ void ActorImpl::set_kill_time(double kill_time)
 
 double ActorImpl::get_kill_time() const
 {
-  return kill_timer_ ? kill_timer_->date : 0.0;
+  return kill_timer_ ? kill_timer_->get_date() : 0.0;
 }
 
 void ActorImpl::yield()
@@ -301,12 +304,7 @@ void ActorImpl::yield()
 
   if (suspended_) {
     XBT_DEBUG("Hey! I'm suspended.");
-
     xbt_assert(exception_ == nullptr, "Gasp! This exception may be lost by subsequent calls.");
-
-    if (waiting_synchro_ != nullptr) // Not sure of when this will happen. Maybe when suspending early in the SR when a
-      waiting_synchro_->suspend();   // waiting_synchro was terminated
-
     yield(); // Yield back to maestro without proceeding with my execution. I'll get rescheduled by resume()
   }
 
@@ -380,10 +378,9 @@ void ActorImpl::suspend()
 
   suspended_ = true;
 
-  /* If the suspended actor is waiting on a sync, suspend its synchronization.
-   * Otherwise, it will suspend itself when scheduled, ie, very soon. */
-  if (waiting_synchro_ != nullptr)
-    waiting_synchro_->suspend();
+  /* Suspend the activities associated with this actor. */
+  for (auto const& activity : activities_)
+    activity->suspend();
 }
 
 void ActorImpl::resume()
@@ -399,10 +396,10 @@ void ActorImpl::resume()
     return;
   suspended_ = false;
 
-  /* resume the activity that was blocking the resumed actor. */
-  if (waiting_synchro_)
-    waiting_synchro_->resume();
-  else // Reschedule the actor if it was forcefully unscheduled in yield()
+  /* resume the activities that were blocked when suspending the actor. */
+  for (auto const& activity : activities_)
+    activity->resume();
+  if (not waiting_synchro_) // Reschedule the actor if it was forcefully unscheduled in yield()
     simix_global->actors_to_run.push_back(this);
 
   XBT_OUT();