@@ -201,7 +201,7 @@ opal_common_ucx_wpool_init(opal_common_ucx_wpool_t *wpool,
201201 goto err_wpool_add ;
202202 }
203203
204- pthread_key_create (& wpool -> tls_key , _tlocal_cleanup );
204+ opal_tsd_key_create (& wpool -> tls_key , _tlocal_cleanup );
205205
206206 return rc ;
207207
@@ -229,7 +229,7 @@ void opal_common_ucx_wpool_finalize(opal_common_ucx_wpool_t *wpool)
229229
230230 /* After this have been called no thread cleanup callback
231231 * will be called */
232- pthread_key_delete (wpool -> tls_key );
232+ opal_tsd_key_delete (wpool -> tls_key );
233233
234234 /* Go over remaining TLS structures and release it */
235235 OPAL_LIST_FOREACH_SAFE (tls_item , tls_next , & wpool -> tls_list ,
@@ -553,7 +553,7 @@ int opal_common_ucx_wpmem_create(opal_common_ucx_ctx_t *ctx,
553553
554554 /* Dont need the destructor here, will use
555555 * wpool-level destructor */
556- pthread_key_create (& mem -> mem_tls_key , NULL );
556+ opal_tsd_key_create (& mem -> mem_tls_key , NULL );
557557
558558 (* mem_ptr ) = mem ;
559559 (* my_mem_addr ) = rkey_addr ;
@@ -641,7 +641,7 @@ static int _comm_ucx_wpmem_map(opal_common_ucx_wpool_t *wpool,
641641
642642static void _common_ucx_wpmem_free (opal_common_ucx_wpmem_t * mem )
643643{
644- pthread_key_delete (mem -> mem_tls_key );
644+ opal_tsd_key_delete (mem -> mem_tls_key );
645645 free (mem -> mem_addrs );
646646 free (mem -> mem_displs );
647647 ucp_mem_unmap (mem -> ctx -> wpool -> ucp_ctx , mem -> memh );
@@ -714,15 +714,21 @@ static _tlocal_table_t* _common_ucx_tls_init(opal_common_ucx_wpool_t *wpool)
714714 return NULL ;
715715 }
716716
717- pthread_setspecific (wpool -> tls_key , tls );
717+ opal_tsd_setspecific (wpool -> tls_key , tls );
718718
719719 return tls ;
720720}
721721
722722static inline _tlocal_table_t *
723723_tlocal_get_tls (opal_common_ucx_wpool_t * wpool ){
724- _tlocal_table_t * tls = pthread_getspecific (wpool -> tls_key );
725- if ( OPAL_UNLIKELY (NULL == tls ) ) {
724+ _tlocal_table_t * tls ;
725+ int rc = opal_tsd_getspecific (wpool -> tls_key , (void * * )& tls );
726+
727+ if (OPAL_SUCCESS != rc ) {
728+ return NULL ;
729+ }
730+
731+ if (OPAL_UNLIKELY (NULL == tls )) {
726732 tls = _common_ucx_tls_init (wpool );
727733 }
728734 return tls ;
@@ -777,7 +783,7 @@ static void _common_ucx_tls_cleanup(_tlocal_table_t *tls)
777783 free (tls -> ctx_tbl [i ]);
778784 }
779785
780- pthread_setspecific (tls -> wpool -> tls_key , NULL );
786+ opal_tsd_setspecific (tls -> wpool -> tls_key , NULL );
781787
782788 OBJ_RELEASE (tls );
783789 return ;
@@ -1033,7 +1039,7 @@ static _tlocal_mem_t *_tlocal_add_mem(_tlocal_table_t *tls,
10331039 calloc (1 , sizeof (* tls -> mem_tbl [free_idx ]-> mem_tls_ptr ));
10341040 tls -> mem_tbl [free_idx ]-> mem_tls_ptr -> winfo = ctx_rec -> winfo ;
10351041 tls -> mem_tbl [free_idx ]-> mem_tls_ptr -> rkeys = tls -> mem_tbl [free_idx ]-> mem -> rkeys ;
1036- pthread_setspecific (mem -> mem_tls_key , tls -> mem_tbl [free_idx ]-> mem_tls_ptr );
1042+ opal_tsd_setspecific (mem -> mem_tls_key , tls -> mem_tbl [free_idx ]-> mem_tls_ptr );
10371043
10381044 /* Make sure that we completed all the data structures before
10391045 * placing the item to the list
0 commit comments