@@ -212,12 +212,13 @@ int ompi_osc_rdma_attach (struct ompi_win_t *win, void *base, size_t len)
212212 return ret ;
213213 }
214214
215+
216+ ompi_osc_rdma_lock_acquire_exclusive (module , my_peer , offsetof (ompi_osc_rdma_state_t , regions_lock ));
217+
215218 /* region is in flux */
216219 module -> state -> region_count = -1 ;
217220 opal_atomic_wmb ();
218221
219- ompi_osc_rdma_lock_acquire_exclusive (module , my_peer , offsetof (ompi_osc_rdma_state_t , regions_lock ));
220-
221222 /* do a binary seach for where the region should be inserted */
222223 if (region_count ) {
223224 region = find_insertion_point ((ompi_osc_rdma_region_t * ) module -> state -> regions , 0 , region_count - 1 ,
@@ -357,6 +358,7 @@ int ompi_osc_rdma_detach (struct ompi_win_t *win, const void *base)
357358 module -> dynamic_handles [region_count - 1 ] = NULL ;
358359
359360 module -> state -> region_count = ((region_id + 1 ) << 32 ) | (region_count - 1 );
361+ opal_atomic_mb ();
360362
361363 ompi_osc_rdma_lock_release_exclusive (module , & my_peer -> super , offsetof (ompi_osc_rdma_state_t , regions_lock ));
362364
@@ -465,6 +467,8 @@ int ompi_osc_rdma_find_dynamic_region (ompi_osc_rdma_module_t *module, ompi_osc_
465467 OSC_RDMA_VERBOSE (MCA_BASE_VERBOSE_TRACE , "locating dynamic memory region matching: {%" PRIx64 ", %" PRIx64 "}"
466468 " (len %lu)" , base , base + len , (unsigned long ) len );
467469
470+ // Make sure region isn't being touched.
471+ ompi_osc_rdma_lock_acquire_exclusive (module , peer , offsetof (ompi_osc_rdma_state_t , regions_lock ));
468472 if (!ompi_osc_rdma_peer_local_state (peer )) {
469473 ret = ompi_osc_rdma_refresh_dynamic_region (module , dy_peer );
470474 if (OMPI_SUCCESS != ret ) {
@@ -478,6 +482,7 @@ int ompi_osc_rdma_find_dynamic_region (ompi_osc_rdma_module_t *module, ompi_osc_
478482 regions = (ompi_osc_rdma_region_t * ) peer_state -> regions ;
479483 region_count = peer_state -> region_count ;
480484 }
485+ ompi_osc_rdma_lock_release_exclusive (module , peer , offsetof (ompi_osc_rdma_state_t , regions_lock ));
481486
482487 * region = ompi_osc_rdma_find_region_containing (regions , 0 , region_count - 1 , (intptr_t ) base , bound , module -> region_size , NULL );
483488 if (!* region ) {
0 commit comments