+ /* Associate this simcall to the synchro */
+ register_simcall(&issuer->simcall_);
+
+ xbt_assert(not MC_is_active() && not MC_record_replay_is_active(), "MC is currently not supported here.");
+
+ /* If the synchro is already finished then perform the error handling */
+ if (state_ != State::RUNNING) {
+ finish();
+ } else {
+ /* we need a sleep action (even when the timeout is infinite) to be notified of host failures */
+ RawImplPtr synchro(new RawImpl([this, issuer]() {
+ this->unregister_simcall(&issuer->simcall_);
+ issuer->waiting_synchro_ = nullptr;
+ auto* observer = dynamic_cast<kernel::actor::ActivityWaitSimcall*>(issuer->simcall_.observer_);
+ xbt_assert(observer != nullptr);
+ observer->set_result(true);
+ }));
+ synchro->set_host(issuer->get_host()).set_timeout(timeout).start();
+ synchro->register_simcall(&issuer->simcall_);
+ }
+}
+
+void ActivityImpl::suspend()
+{
+ if (surf_action_ == nullptr)
+ return;
+ XBT_VERB("This activity is suspended (remain: %f)", surf_action_->get_remains());
+ surf_action_->suspend();
+ on_suspended(*this);
+}
+
+void ActivityImpl::resume()
+{
+ if (surf_action_ == nullptr)
+ return;
+ XBT_VERB("This activity is resumed (remain: %f)", surf_action_->get_remains());
+ surf_action_->resume();
+ on_resumed(*this);
+}
+
+void ActivityImpl::cancel()
+{
+ XBT_VERB("Activity %p is canceled", this);
+ if (surf_action_ != nullptr)
+ surf_action_->cancel();
+ state_ = State::CANCELED;
+}
+
+// boost::intrusive_ptr<Activity> support:
+void intrusive_ptr_add_ref(ActivityImpl* activity)
+{
+ activity->refcount_.fetch_add(1, std::memory_order_relaxed);
+}
+
+void intrusive_ptr_release(ActivityImpl* activity)
+{
+ if (activity->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
+ std::atomic_thread_fence(std::memory_order_acquire);
+ delete activity;
+ }
+}
+xbt::signal<void(ActivityImpl const&)> ActivityImpl::on_resumed;
+xbt::signal<void(ActivityImpl const&)> ActivityImpl::on_suspended;
+}