+smx_activity_t ActorImpl::suspend(ActorImpl* issuer)
+{
+ if (suspended_) {
+ XBT_DEBUG("Actor '%s' is already suspended", get_cname());
+ return nullptr;
+ }
+
+ suspended_ = true;
+
+ /* If we are suspending another actor that is waiting on a sync, suspend its synchronization. */
+ if (this != issuer) {
+ if (waiting_synchro)
+ waiting_synchro->suspend();
+ /* If the other actor is not waiting, its suspension is delayed to when the actor is rescheduled. */
+
+ return nullptr;
+ } else {
+ return SIMIX_execution_start("suspend", "", 0.0, 1.0, 0.0, this->host_);
+ }
+}
+
+void ActorImpl::resume()
+{
+ XBT_IN("process = %p", this);
+
+ if (context_->iwannadie) {
+ XBT_VERB("Ignoring request to suspend an actor that is currently dying.");
+ return;
+ }
+
+ if (not suspended_)
+ return;
+ suspended_ = false;
+
+ /* resume the synchronization that was blocking the resumed actor. */
+ if (waiting_synchro)
+ waiting_synchro->resume();
+
+ XBT_OUT();
+}
+
+smx_activity_t ActorImpl::sleep(double duration)
+{
+ if (host_->is_off())
+ throw_exception(std::make_exception_ptr(simgrid::HostFailureException(
+ XBT_THROW_POINT, std::string("Host ") + std::string(host_->get_cname()) + " failed, you cannot sleep there.")));
+
+ simgrid::kernel::activity::SleepImpl* synchro = new simgrid::kernel::activity::SleepImpl();
+ synchro->host = host_;
+ synchro->surf_sleep = host_->pimpl_cpu->sleep(duration);
+ synchro->surf_sleep->set_data(synchro);
+ XBT_DEBUG("Create sleep synchronization %p", synchro);
+
+ return synchro;
+}
+
+void ActorImpl::throw_exception(std::exception_ptr e)
+{
+ exception = e;
+
+ if (suspended_)
+ resume();
+
+ /* cancel the blocking synchro if any */
+ if (waiting_synchro) {
+
+ simgrid::kernel::activity::ExecImplPtr exec =
+ boost::dynamic_pointer_cast<simgrid::kernel::activity::ExecImpl>(waiting_synchro);
+ if (exec != nullptr && exec->surf_action_)
+ exec->surf_action_->cancel();
+
+ simgrid::kernel::activity::CommImplPtr comm =
+ boost::dynamic_pointer_cast<simgrid::kernel::activity::CommImpl>(waiting_synchro);
+ if (comm != nullptr) {
+ comms.remove(comm);
+ comm->cancel();
+ }
+
+ simgrid::kernel::activity::SleepImplPtr sleep =
+ boost::dynamic_pointer_cast<simgrid::kernel::activity::SleepImpl>(waiting_synchro);
+ if (sleep != nullptr) {
+ SIMIX_process_sleep_destroy(waiting_synchro);
+ if (std::find(begin(simix_global->process_to_run), end(simix_global->process_to_run), this) ==
+ end(simix_global->process_to_run) &&
+ this != SIMIX_process_self()) {
+ XBT_DEBUG("Inserting %s in the to_run list", get_cname());
+ simix_global->process_to_run.push_back(this);
+ }
+ }
+
+ simgrid::kernel::activity::RawImplPtr raw =
+ boost::dynamic_pointer_cast<simgrid::kernel::activity::RawImpl>(waiting_synchro);
+ if (raw != nullptr) {
+ SIMIX_synchro_stop_waiting(this, &simcall);
+ }
+
+ simgrid::kernel::activity::IoImplPtr io =
+ boost::dynamic_pointer_cast<simgrid::kernel::activity::IoImpl>(waiting_synchro);
+ if (io != nullptr) {
+ delete io.get();
+ }
+ }
+ waiting_synchro = nullptr;
+}
+
+void create_maestro(simgrid::simix::ActorCode code)