- switch (state_) {
- case State::FAILED:
- simcall->issuer_->context_->set_wannadie();
- simcall->issuer_->exception_ =
- std::make_exception_ptr(StorageFailureException(XBT_THROW_POINT, "Storage failed"));
- break;
- case State::CANCELED:
- simcall->issuer_->exception_ = std::make_exception_ptr(CancelException(XBT_THROW_POINT, "I/O Canceled"));
- break;
- case State::TIMEOUT:
- simcall->issuer_->exception_ = std::make_exception_ptr(simgrid::TimeoutException(XBT_THROW_POINT, "Timeouted"));
- break;
- default:
- xbt_assert(state_ == State::DONE, "Internal error in IoImpl::finish(): unexpected synchro state %s",
- to_c_str(state_));
+
+ /* If a waitany simcall is waiting for this synchro to finish, then remove it from the other synchros in the waitany
+ * list. Afterwards, get the position of the actual synchro in the waitany list and return it as the result of the
+ * simcall */
+
+ if (simcall->call_ == simix::Simcall::NONE) // FIXME: maybe a better way to handle this case
+ continue; // if process handling comm is killed
+ if (auto* observer = dynamic_cast<kernel::actor::IoWaitanySimcall*>(simcall->observer_)) { // simcall is a wait_any?
+ const auto& ios = observer->get_ios();
+
+ for (auto* io : ios) {
+ io->unregister_simcall(simcall);
+
+ if (simcall->timeout_cb_) {
+ simcall->timeout_cb_->remove();
+ simcall->timeout_cb_ = nullptr;
+ }
+ }
+
+ if (not MC_is_active() && not MC_record_replay_is_active()) {
+ auto element = std::find(ios.begin(), ios.end(), this);
+ int rank = element != ios.end() ? static_cast<int>(std::distance(ios.begin(), element)) : -1;
+ observer->set_result(rank);
+ }