diff --git a/ompi/runtime/ompi_rte.c b/ompi/runtime/ompi_rte.c index 876bf14ee8..9e4eba1b30 100644 --- a/ompi/runtime/ompi_rte.c +++ b/ompi/runtime/ompi_rte.c @@ -78,7 +78,7 @@ static int _setup_proc_session_dir(char **sdir); #define OPAL_PRINT_NAME_ARG_NUM_BUFS 16 static bool fns_init=false; -static opal_tsd_key_t print_args_tsd_key; +static opal_tsd_tracked_key_t print_args_tsd_key; static char* opal_print_args_null = "NULL"; typedef struct { char *buffers[OPAL_PRINT_NAME_ARG_NUM_BUFS]; @@ -108,14 +108,12 @@ get_print_name_buffer(void) if (!fns_init) { /* setup the print_args function */ - if (OPAL_SUCCESS != (ret = opal_tsd_key_create(&print_args_tsd_key, buffer_cleanup))) { - OPAL_ERROR_LOG(ret); - return NULL; - } + OBJ_CONSTRUCT(&print_args_tsd_key, opal_tsd_tracked_key_t); + opal_tsd_tracked_key_set_destructor(&print_args_tsd_key, buffer_cleanup); fns_init = true; } - ret = opal_tsd_get(print_args_tsd_key, (void**)&ptr); + ret = opal_tsd_tracked_key_get(&print_args_tsd_key, (void**)&ptr); if (OPAL_SUCCESS != ret) return NULL; if (NULL == ptr) { @@ -124,7 +122,7 @@ get_print_name_buffer(void) ptr->buffers[i] = (char *) malloc((OPAL_PRINT_NAME_ARGS_MAX_SIZE+1) * sizeof(char)); } ptr->cntr = 0; - ret = opal_tsd_set(print_args_tsd_key, (void*)ptr); + ret = opal_tsd_tracked_key_set(&print_args_tsd_key, (void*)ptr); } return (opal_print_args_buffers_t*) ptr; @@ -940,6 +938,10 @@ int ompi_rte_finalize(void) opal_process_info.initial_errhandler = NULL; } + if (fns_init) { + OBJ_DESTRUCT(&print_args_tsd_key); + } + /* cleanup our internal nspace hack */ opal_pmix_finalize_nspace_tracker(); diff --git a/opal/mca/common/ucx/common_ucx_wpool.c b/opal/mca/common/ucx/common_ucx_wpool.c index 4efe79fd45..62d1ce5500 100644 --- a/opal/mca/common/ucx/common_ucx_wpool.c +++ b/opal/mca/common/ucx/common_ucx_wpool.c @@ -207,8 +207,8 @@ opal_common_ucx_wpool_init(opal_common_ucx_wpool_t *wpool, goto err_wpool_add; } - opal_tsd_key_create(&wpool->tls_key, _tlocal_cleanup); - + OBJ_CONSTRUCT(&wpool->tls_key, opal_tsd_tracked_key_t); + opal_tsd_tracked_key_set_destructor(&wpool->tls_key, _tlocal_cleanup); return rc; err_wpool_add: @@ -235,7 +235,7 @@ void opal_common_ucx_wpool_finalize(opal_common_ucx_wpool_t *wpool) /* After this have been called no thread cleanup callback * will be called */ - opal_tsd_key_delete(wpool->tls_key); + OBJ_DESTRUCT(&wpool->tls_key); /* Go over remaining TLS structures and release it */ OPAL_LIST_FOREACH_SAFE(tls_item, tls_next, &wpool->tls_list, @@ -565,7 +565,7 @@ int opal_common_ucx_wpmem_create(opal_common_ucx_ctx_t *ctx, /* Dont need the destructor here, will use * wpool-level destructor */ - opal_tsd_key_create(&mem->mem_tls_key, NULL); + OBJ_CONSTRUCT(&mem->mem_tls_key, opal_tsd_tracked_key_t); (*mem_ptr) = mem; (*my_mem_addr) = rkey_addr; @@ -653,7 +653,7 @@ static int _comm_ucx_wpmem_map(opal_common_ucx_wpool_t *wpool, static void _common_ucx_wpmem_free(opal_common_ucx_wpmem_t *mem) { - opal_tsd_key_delete(mem->mem_tls_key); + OBJ_DESTRUCT(&mem->mem_tls_key); free(mem->mem_addrs); free(mem->mem_displs); ucp_mem_unmap(mem->ctx->wpool->ucp_ctx, mem->memh); @@ -726,7 +726,7 @@ static _tlocal_table_t* _common_ucx_tls_init(opal_common_ucx_wpool_t *wpool) return NULL; } - opal_tsd_set(wpool->tls_key, tls); + opal_tsd_tracked_key_set(&wpool->tls_key, tls); return tls; } @@ -734,7 +734,7 @@ static _tlocal_table_t* _common_ucx_tls_init(opal_common_ucx_wpool_t *wpool) static inline _tlocal_table_t * _tlocal_get_tls(opal_common_ucx_wpool_t *wpool){ _tlocal_table_t *tls; - int rc = opal_tsd_get(wpool->tls_key, (void**)&tls); + int rc = opal_tsd_tracked_key_get(&wpool->tls_key, (void**)&tls); if (OPAL_SUCCESS != rc) { return NULL; @@ -795,7 +795,7 @@ static void _common_ucx_tls_cleanup(_tlocal_table_t *tls) free(tls->ctx_tbl[i]); } - opal_tsd_set(tls->wpool->tls_key, NULL); + opal_tsd_tracked_key_set(&tls->wpool->tls_key, NULL); OBJ_RELEASE(tls); return; @@ -1051,7 +1051,7 @@ static _tlocal_mem_t *_tlocal_add_mem(_tlocal_table_t *tls, calloc(1, sizeof(*tls->mem_tbl[free_idx]->mem_tls_ptr)); tls->mem_tbl[free_idx]->mem_tls_ptr->winfo = ctx_rec->winfo; tls->mem_tbl[free_idx]->mem_tls_ptr->rkeys = tls->mem_tbl[free_idx]->mem->rkeys; - opal_tsd_set(mem->mem_tls_key, tls->mem_tbl[free_idx]->mem_tls_ptr); + opal_tsd_tracked_key_set(&mem->mem_tls_key, tls->mem_tbl[free_idx]->mem_tls_ptr); /* Make sure that we completed all the data structures before * placing the item to the list diff --git a/opal/mca/common/ucx/common_ucx_wpool.h b/opal/mca/common/ucx/common_ucx_wpool.h index 390ec9e78d..241af7e2bd 100644 --- a/opal/mca/common/ucx/common_ucx_wpool.h +++ b/opal/mca/common/ucx/common_ucx_wpool.h @@ -48,7 +48,7 @@ typedef struct { /* Thread-local key to allow each thread to have * local information assisiated with this wpool */ - opal_tsd_key_t tls_key; + opal_tsd_tracked_key_t tls_key; /* Bookkeeping information */ opal_list_t idle_workers; @@ -107,7 +107,7 @@ typedef struct { /* TLS item that allows each thread to * store endpoints and rkey arrays * for faster access */ - opal_tsd_key_t mem_tls_key; + opal_tsd_tracked_key_t mem_tls_key; } opal_common_ucx_wpmem_t; /* The structure that wraps UCP worker and holds the state that is required @@ -201,7 +201,7 @@ opal_common_ucx_tlocal_fetch(opal_common_ucx_wpmem_t *mem, int target, int rc = OPAL_SUCCESS; /* First check the fast-path */ - rc = opal_tsd_get(mem->mem_tls_key, (void**)&fp); + rc = opal_tsd_tracked_key_get(&mem->mem_tls_key, (void**)&fp); if (OPAL_SUCCESS != rc) { return rc; } @@ -212,7 +212,7 @@ opal_common_ucx_tlocal_fetch(opal_common_ucx_wpmem_t *mem, int target, if (OPAL_SUCCESS != rc) { return rc; } - rc = opal_tsd_get(mem->mem_tls_key, (void**)&fp); + rc = opal_tsd_tracked_key_get(&mem->mem_tls_key, (void**)&fp); if (OPAL_SUCCESS != rc) { return rc; } diff --git a/opal/mca/hwloc/base/hwloc_base_frame.c b/opal/mca/hwloc/base/hwloc_base_frame.c index bfdb4a8e13..39ececdb64 100644 --- a/opal/mca/hwloc/base/hwloc_base_frame.c +++ b/opal/mca/hwloc/base/hwloc_base_frame.c @@ -243,6 +243,8 @@ static int opal_hwloc_base_open(mca_base_open_flag_t flags) return OPAL_SUCCESS; } +static opal_tsd_tracked_key_t *print_tsd_key = NULL; + static int opal_hwloc_base_close(void) { int ret; @@ -250,6 +252,11 @@ static int opal_hwloc_base_close(void) return OPAL_SUCCESS; } + if (NULL != print_tsd_key) { + OBJ_RELEASE(print_tsd_key); + print_tsd_key = NULL; + } + /* no need to close the component as it was statically opened */ /* for support of tools such as ompi_info */ @@ -277,7 +284,6 @@ static int opal_hwloc_base_close(void) } static bool fns_init=false; -static opal_tsd_key_t print_tsd_key; char* opal_hwloc_print_null = "NULL"; static void buffer_cleanup(void *value) @@ -301,13 +307,12 @@ opal_hwloc_print_buffers_t *opal_hwloc_get_print_buffer(void) if (!fns_init) { /* setup the print_args function */ - if (OPAL_SUCCESS != (ret = opal_tsd_key_create(&print_tsd_key, buffer_cleanup))) { - return NULL; - } + print_tsd_key = OBJ_NEW(opal_tsd_tracked_key_t); + opal_tsd_tracked_key_set_destructor(print_tsd_key, buffer_cleanup); fns_init = true; } - ret = opal_tsd_get(print_tsd_key, (void**)&ptr); + ret = opal_tsd_tracked_key_get(print_tsd_key, (void**)&ptr); if (OPAL_SUCCESS != ret) return NULL; if (NULL == ptr) { @@ -316,7 +321,7 @@ opal_hwloc_print_buffers_t *opal_hwloc_get_print_buffer(void) ptr->buffers[i] = (char *) malloc((OPAL_HWLOC_PRINT_MAX_SIZE+1) * sizeof(char)); } ptr->cntr = 0; - ret = opal_tsd_set(print_tsd_key, (void*)ptr); + ret = opal_tsd_tracked_key_set(print_tsd_key, (void*)ptr); } return (opal_hwloc_print_buffers_t*) ptr; diff --git a/opal/util/net.c b/opal/util/net.c index fb5e1822e0..7c16d03d5d 100644 --- a/opal/util/net.c +++ b/opal/util/net.c @@ -105,7 +105,7 @@ typedef struct private_ipv4_t { static private_ipv4_t* private_ipv4 = NULL; #if OPAL_ENABLE_IPV6 -static opal_tsd_key_t hostname_tsd_key; +static opal_tsd_tracked_key_t *hostname_tsd_key = NULL; static void @@ -121,12 +121,12 @@ get_hostname_buffer(void) void *buffer; int ret; - ret = opal_tsd_get(hostname_tsd_key, &buffer); + ret = opal_tsd_tracked_key_get(hostname_tsd_key, &buffer); if (OPAL_SUCCESS != ret) return NULL; if (NULL == buffer) { buffer = (void*) malloc((NI_MAXHOST + 1) * sizeof(char)); - ret = opal_tsd_set(hostname_tsd_key, buffer); + ret = opal_tsd_tracked_key_set(hostname_tsd_key, buffer); } return (char*) buffer; @@ -144,6 +144,12 @@ get_hostname_buffer(void) */ static void opal_net_finalize (void) { +#if OPAL_ENABLE_IPV6 + if (NULL != hostname_tsd_key) { + OBJ_RELEASE(hostname_tsd_key); + hostname_tsd_key = NULL; + } +#endif free(private_ipv4); private_ipv4 = NULL; } @@ -192,10 +198,10 @@ opal_net_init(void) do_local_init: #if OPAL_ENABLE_IPV6 - return opal_tsd_key_create(&hostname_tsd_key, hostname_cleanup); -#else - return OPAL_SUCCESS; + hostname_tsd_key = OBJ_NEW(opal_tsd_tracked_key_t); + opal_tsd_tracked_key_set_destructor(hostname_tsd_key, hostname_cleanup); #endif + return OPAL_SUCCESS; } /* convert a CIDR prefixlen to netmask (in network byte order) */