+ auto* observer = dynamic_cast<kernel::actor::ActivityTestanySimcall*>(issuer->simcall_.observer_);
+ xbt_assert(observer != nullptr);
+
+ if (MC_is_active() || MC_record_replay_is_active()) {
+ int idx = observer->get_value();
+ xbt_assert(idx == -1 || activities[idx]->test(issuer));
+ return idx;
+ }
+
+ for (std::size_t i = 0; i < activities.size(); ++i) {
+ if (activities[i]->test(issuer)) {
+ observer->set_result(i);
+ return i;
+ }
+ }
+ return -1;
+}
+
+void ActivityImpl::wait_for(actor::ActorImpl* issuer, double timeout)
+{
+ XBT_DEBUG("Wait for execution of synchro %p, state %s", this, get_state_str());
+ xbt_assert(std::isfinite(timeout), "timeout is not finite!");
+
+ /* 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::WAITING && state_ != State::RUNNING) {
+ finish();
+ } else {
+ /* As Messages in Message Queues are virtually instantaneous, we do not need a timeout */
+ /* Or maybe we do, and will have to implement a specific way to handle them is need arises */
+ if (dynamic_cast<MessImpl*>(this) != nullptr)
+ return;
+ /* we need a sleep action (even when the timeout is infinite) to be notified of host failures */
+ /* Comms handle that a bit differently of the other activities */
+ if (auto* comm = dynamic_cast<CommImpl*>(this)) {
+ resource::Action* sleep_action = issuer->get_host()->get_cpu()->sleep(timeout);
+ sleep_action->set_activity(comm);
+
+ if (issuer == comm->src_actor_)
+ comm->src_timeout_.reset(sleep_action);
+ else
+ comm->dst_timeout_.reset(sleep_action);
+ } else {
+ SynchroImplPtr synchro(new SynchroImpl([this, issuer]() {
+ this->unregister_simcall(&issuer->simcall_);
+ issuer->waiting_synchro_ = nullptr;
+ issuer->exception_ = nullptr;
+ auto* observer = dynamic_cast<kernel::actor::ActivityWaitSimcall*>(issuer->simcall_.observer_);
+ xbt_assert(observer != nullptr);
+ observer->set_result(true); // Returns that the wait_for timeouted
+ }));
+ synchro->set_host(issuer->get_host()).set_timeout(timeout).start();
+ synchro->register_simcall(&issuer->simcall_);
+ }
+ }
+}
+
+void ActivityImpl::wait_any_for(actor::ActorImpl* issuer, const std::vector<ActivityImpl*>& activities, double timeout)
+{
+ XBT_DEBUG("Wait for execution of any synchro");
+ if (MC_is_active() || MC_record_replay_is_active()) {
+ auto* observer = dynamic_cast<kernel::actor::ActivityWaitanySimcall*>(issuer->simcall_.observer_);
+ xbt_assert(observer != nullptr);
+ xbt_assert(timeout <= 0.0, "Timeout not implemented for waitany in the model-checker");
+ if (int idx = observer->get_value(); idx != -1) {
+ auto* act = activities.at(idx);
+ act->register_simcall(&issuer->simcall_);
+ observer->set_result(idx);
+ act->set_state(State::DONE);
+ act->finish();
+ }