Skip to content

Commit 578d881

Browse files
author
Ralph Castain
authored
Merge pull request #2982 from rhc54/topic/threadstop
Cleanup PMIx shutdown
2 parents f7fe2f7 + 9cd7349 commit 578d881

File tree

4 files changed

+44
-43
lines changed

4 files changed

+44
-43
lines changed

opal/mca/pmix/pmix2x/pmix/src/client/pmix_client.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,11 @@ PMIX_EXPORT pmix_status_t PMIx_Finalize(const pmix_info_t info[], size_t ninfo)
459459
}
460460

461461
if (!pmix_globals.external_evbase) {
462-
/* stop the progress thread */
463-
(void)pmix_progress_thread_stop(NULL);
462+
/* stop the progress thread, but leave the event base
463+
* still constructed. This will allow us to safely
464+
* tear down the infrastructure, including removal
465+
* of any events objects may be holding */
466+
(void)pmix_progress_thread_pause(NULL);
464467
}
465468

466469
PMIX_DESTRUCT(&pmix_client_globals.myserver);
@@ -472,17 +475,13 @@ PMIX_EXPORT pmix_status_t PMIx_Finalize(const pmix_info_t info[], size_t ninfo)
472475
}
473476
#endif
474477

475-
pmix_rte_finalize();
476-
477478
PMIX_LIST_DESTRUCT(&pmix_client_globals.pending_requests);
478479

479480
if (0 <= pmix_client_globals.myserver.sd) {
480481
CLOSE_THE_SOCKET(pmix_client_globals.myserver.sd);
481482
}
482483

483-
pmix_bfrop_close();
484-
485-
pmix_class_finalize();
484+
pmix_rte_finalize();
486485

487486
return PMIX_SUCCESS;
488487
}

opal/mca/pmix/pmix2x/pmix/src/runtime/pmix_finalize.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,8 @@ void pmix_rte_finalize(void)
101101
much */
102102
pmix_output_finalize();
103103

104-
#if 0
105104
/* close the bfrops */
106-
(void)pmix_mca_base_framework_close(&pmix_bfrops_base_framework);
107-
#endif
105+
pmix_bfrop_close();
108106

109107
/* clean out the globals */
110108
PMIX_RELEASE(pmix_globals.mypeer);
@@ -117,7 +115,14 @@ void pmix_rte_finalize(void)
117115
}
118116
PMIX_DESTRUCT(&pmix_globals.events);
119117

120-
#if PMIX_NO_LIB_DESTRUCTOR
121-
pmix_cleanup();
122-
#endif
118+
/* now safe to release the event base */
119+
if (!pmix_globals.external_evbase) {
120+
(void)pmix_progress_thread_stop(NULL);
121+
}
122+
123+
124+
#if PMIX_NO_LIB_DESTRUCTOR
125+
pmix_cleanup();
126+
#endif
127+
123128
}

opal/mca/pmix/pmix2x/pmix/src/server/pmix_server.c

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,30 @@ PMIX_EXPORT pmix_status_t PMIx_server_init(pmix_server_module_t *module,
227227
return PMIX_SUCCESS;
228228
}
229229

230-
static void cleanup_server_state(void)
230+
PMIX_EXPORT pmix_status_t PMIx_server_finalize(void)
231231
{
232232
int i;
233233
pmix_peer_t *peer;
234234

235+
if (1 != pmix_globals.init_cntr) {
236+
--pmix_globals.init_cntr;
237+
return PMIX_SUCCESS;
238+
}
239+
pmix_globals.init_cntr = 0;
240+
241+
pmix_output_verbose(2, pmix_globals.debug_output,
242+
"pmix:server finalize called");
243+
244+
if (!pmix_globals.external_evbase) {
245+
/* stop the progress thread, but leave the event base
246+
* still constructed. This will allow us to safely
247+
* tear down the infrastructure, including removal
248+
* of any events objects may be holding */
249+
(void)pmix_progress_thread_pause(NULL);
250+
}
251+
252+
pmix_ptl_base_stop_listening();
253+
235254
for (i=0; i < pmix_server_globals.clients.size; i++) {
236255
if (NULL != (peer = (pmix_peer_t*)pmix_pointer_array_get_item(&pmix_server_globals.clients, i))) {
237256
PMIX_RELEASE(peer);
@@ -255,33 +274,10 @@ static void cleanup_server_state(void)
255274

256275
pmix_bfrop_close();
257276
pmix_rte_finalize();
258-
}
259277

260-
PMIX_EXPORT pmix_status_t PMIx_server_finalize(void)
261-
{
262-
if (1 != pmix_globals.init_cntr) {
263-
--pmix_globals.init_cntr;
264-
return PMIX_SUCCESS;
265-
}
266-
pmix_globals.init_cntr = 0;
267-
268-
pmix_output_verbose(2, pmix_globals.debug_output,
269-
"pmix:server finalize called");
270-
271-
if (!pmix_globals.external_evbase) {
272-
/* stop the progress thread */
273-
(void)pmix_progress_thread_stop(NULL);
274-
}
275-
276-
pmix_ptl_base_stop_listening();
277-
278-
cleanup_server_state();
279278
pmix_output_verbose(2, pmix_globals.debug_output,
280279
"pmix:server finalize complete");
281280

282-
/* finalize the class/object system */
283-
pmix_class_finalize();
284-
285281
return PMIX_SUCCESS;
286282
}
287283

opal/mca/pmix/pmix2x/pmix/src/tool/pmix_tool.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -518,17 +518,18 @@ PMIX_EXPORT pmix_status_t PMIx_tool_finalize(void)
518518
"pmix:tool finalize sync received");
519519

520520
if (!pmix_globals.external_evbase) {
521-
/* stop the progress thread */
522-
(void)pmix_progress_thread_stop(NULL);
521+
/* stop the progress thread, but leave the event base
522+
* still constructed. This will allow us to safely
523+
* tear down the infrastructure, including removal
524+
* of any events objects may be holding */
525+
(void)pmix_progress_thread_pause(NULL);
523526
}
524527

525-
/* shutdown services */
526-
pmix_rte_finalize();
527-
528528
PMIX_DESTRUCT(&pmix_client_globals.myserver);
529529
PMIX_LIST_DESTRUCT(&pmix_client_globals.pending_requests);
530530

531-
pmix_class_finalize();
531+
/* shutdown services */
532+
pmix_rte_finalize();
532533

533534
return PMIX_SUCCESS;
534535
}

0 commit comments

Comments
 (0)