]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/posix-process: Consolidate assignment of pthread parent and self
authorMichalis Pappas <michalis@unikraft.io>
Mon, 7 Apr 2025 09:50:17 +0000 (11:50 +0200)
committerUnikraft Bot <monkey@unikraft.io>
Wed, 30 Apr 2025 09:42:51 +0000 (09:42 +0000)
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 <michalis@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1627

lib/posix-process/process.c

index ecb9e4debbae33c7505d72e125131af4907e2782..ac2ce44b8ae93323d29d461d997b83affdc9ecb7 100644 (file)
@@ -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))