From: Michalis Pappas Date: Mon, 7 Apr 2025 09:50:17 +0000 (+0200) Subject: lib/posix-process: Consolidate assignment of pthread parent and self X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=9e6cf9c0885ff096e9251e0d095b03afdcd7d394;p=unikraft%2Funikraft.git lib/posix-process: Consolidate assignment of pthread parent and self uk_posix_process_create() is missing the assignment of pthread_self. Instead of having wrappers perform these assignments of parent and self, move these assignments to the core functions that create and release threads. Signed-off-by: Michalis Pappas Approved-by: Andrei Tatar Reviewed-by: Sergiu Moga Reviewed-by: Andrei Tatar GitHub-Closes: #1627 --- diff --git a/lib/posix-process/process.c b/lib/posix-process/process.c index ecb9e4deb..ac2ce44b8 100644 --- a/lib/posix-process/process.c +++ b/lib/posix-process/process.c @@ -149,9 +149,12 @@ struct posix_thread *pprocess_create_pthread(struct posix_process *pprocess, pthread->_a = a; pthread->process = pprocess; + pthread->parent = uk_pthread_current(); pthread->tid = tid; pthread->thread = th; + uk_thread_uktls_var(th, pthread_self) = pthread; + #if CONFIG_LIBPOSIX_PROCESS_SIGNAL err = pprocess_signal_tdesc_alloc(pthread); if (unlikely(err)) { @@ -203,6 +206,8 @@ static void pprocess_release_pthread(struct posix_thread *pthread) pprocess_signal_tdesc_free(pthread); #endif /* CONFIG_LIBPOSIX_PROCESS_SIGNAL */ + uk_thread_uktls_var(pthread->thread, pthread_self) = NULL; + /* remove from process' thread list */ uk_list_del_init(&pthread->thread_list_entry); @@ -312,6 +317,8 @@ int pprocess_create(struct uk_alloc *a, uk_list_add_tail(&(*pthread)->thread_list_entry, &pprocess->threads); + /* Update parent */ + (*pthread)->parent = parent_pthread; #if CONFIG_LIBPOSIX_PROCESS_SIGNAL /* Reset signal state of this thread */ ret = pprocess_signal_tdesc_init(*pthread); @@ -333,8 +340,6 @@ int pprocess_create(struct uk_alloc *a, goto err_free_pprocess; } - (*pthread)->parent = parent_pthread; - pprocess->parent = parent_pprocess; if (parent_pprocess) { uk_list_add_tail(&pprocess->child_list_entry, @@ -523,7 +528,6 @@ static void posix_thread_fini(struct uk_thread *child) child, child->name, (int) pthread_self->tid, (int) pprocess->pid); pprocess_release_pthread(pthread_self); - pthread_self = NULL; /* Release process if it became empty of threads */ if (uk_list_empty(&pprocess->threads))