- bar_->wait();
-
- flush_local_all();
-
- if (info_ != MPI_INFO_NULL)
- simgrid::smpi::Info::unref(info_);
- if (errhandler_ != MPI_ERRHANDLER_NULL)
- simgrid::smpi::Errhandler::unref(errhandler_);
-
- comm_->remove_rma_win(this);
-
- colls::barrier(comm_);
- Comm::unref(comm_);
-
- if (rank_ == 0)
- delete bar_;
+ if (MC_is_active() || MC_record_replay_is_active())
+ win->bar_->wait();
+ else
+ colls::barrier(win->comm_);
+ win->flush_local_all();
+
+ if (win->info_ != MPI_INFO_NULL)
+ simgrid::smpi::Info::unref(win->info_);
+ if (win->errhandler_ != MPI_ERRHANDLER_NULL)
+ simgrid::smpi::Errhandler::unref(win->errhandler_);
+
+ win->comm_->remove_rma_win(win);
+
+ colls::barrier(win->comm_);
+ Comm::unref(win->comm_);
+ if (not win->lockers_.empty() || win->opened_ < 0) {
+ XBT_WARN("Freeing a locked or opened window");
+ return MPI_ERR_WIN;
+ }
+ if (win->allocated_)
+ xbt_free(win->base_);
+ for (auto m : {win->mut_, win->lock_mut_, win->atomic_mut_})
+ if (m->get_owner() != nullptr)
+ m->unlock();