|
18 | 18 | #include "opal/mca/threads/threads.h" |
19 | 19 |
|
20 | 20 | #include "ompi/runtime/params.h" |
| 21 | +#include "opal/sys/atomic.h" |
21 | 22 | #include "ompi/communicator/communicator.h" |
22 | 23 | #include "ompi/mca/pml/pml.h" |
23 | 24 | #include "ompi/mca/bml/bml.h" |
@@ -94,7 +95,7 @@ static opal_event_base_t* fd_event_base = NULL; |
94 | 95 | static void fd_event_cb(int fd, short flags, void* pdetector); |
95 | 96 |
|
96 | 97 | static bool comm_detector_use_thread = false; |
97 | | -static opal_atomic_int32_t fd_thread_active = 0; |
| 98 | +static opal_atomic_int32_t fd_thread_active = OPAL_ATOMIC_INIT(0); |
98 | 99 | static opal_thread_t fd_thread; |
99 | 100 | static void* fd_progress(opal_object_t* obj); |
100 | 101 |
|
@@ -168,8 +169,9 @@ int ompi_comm_failure_detector_init(void) { |
168 | 169 | fd_thread.t_arg = NULL; |
169 | 170 | ret = opal_thread_start(&fd_thread); |
170 | 171 | if( OPAL_SUCCESS != ret ) goto cleanup; |
171 | | - while( 0 == fd_thread_active ); /* wait for the fd thread initialization */ |
172 | | - if( 0 > fd_thread_active ) goto cleanup; |
| 172 | + while (0 == opal_atomic_load_32(&fd_thread_active)) { /* wait for the fd thread initialization */ |
| 173 | + } |
| 174 | + if (0 > opal_atomic_load_32(&fd_thread_active)) goto cleanup; |
173 | 175 | } |
174 | 176 |
|
175 | 177 | return OMPI_SUCCESS; |
@@ -218,18 +220,19 @@ int ompi_comm_failure_detector_finalize(void) { |
218 | 220 | #endif |
219 | 221 | while( observing == detector->hb_observing ) { |
220 | 222 | /* If observed process changed, recheck if local*/ |
221 | | - if( !(0 < fd_thread_active) ) |
| 223 | + if (!(0 < opal_atomic_load_32(&fd_thread_active))) |
222 | 224 | { |
223 | 225 | opal_progress(); |
224 | 226 | } |
225 | 227 | } |
226 | 228 | } |
227 | 229 |
|
228 | | - if( 0 < fd_thread_active ) { |
| 230 | + if (0 < opal_atomic_load_32(&fd_thread_active)) { |
229 | 231 | void* tret; |
230 | 232 | /* this is not a race condition. Accesses are serialized, we use the |
231 | 233 | * atomic for the mfence part of it. */ |
232 | | - OPAL_THREAD_ADD_FETCH32(&fd_thread_active, -fd_thread_active); |
| 234 | + int32_t active = opal_atomic_load_32(&fd_thread_active); |
| 235 | + OPAL_THREAD_ADD_FETCH32(&fd_thread_active, -active); |
233 | 236 | opal_event_base_loopbreak(fd_event_base); |
234 | 237 | opal_thread_join(&fd_thread, &tret); |
235 | 238 | } |
@@ -587,9 +590,10 @@ void* fd_progress(opal_object_t* obj) { |
587 | 590 | return OPAL_THREAD_CANCELLED; |
588 | 591 | } |
589 | 592 | OPAL_THREAD_ADD_FETCH32(&fd_thread_active, 1); |
590 | | - while( 1 == fd_thread_active ); /* wait for init stage 2: start_detector */ |
| 593 | + while (1 == opal_atomic_load_32(&fd_thread_active)) { /* wait for init stage 2: start_detector */ |
| 594 | + } |
591 | 595 | ret = MCA_PML_CALL(irecv(NULL, 0, MPI_BYTE, 0, MCA_COLL_BASE_TAG_FT_END, &ompi_mpi_comm_self.comm, &req)); |
592 | | - while( fd_thread_active ) { |
| 596 | + while (opal_atomic_load_32(&fd_thread_active)) { |
593 | 597 | opal_event_loop(fd_event_base, OPAL_EVLOOP_ONCE); |
594 | 598 | #if 0 |
595 | 599 | /* This test disabled because rdma emulation over TCP would not work without |
|
0 commit comments