From 4b8d296e053f5f7062b305adaeeebf4b4ab54689 Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Mon, 8 Jun 2026 14:36:06 -0700 Subject: [PATCH] util/thread: Flush traces at thread exit Signed-off-by: Rob Clark Part-of: --- src/util/u_thread.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/util/u_thread.c b/src/util/u_thread.c index 3a8785cec92..d1cf0858c61 100644 --- a/src/util/u_thread.c +++ b/src/util/u_thread.c @@ -6,6 +6,7 @@ */ #include "util/u_thread.h" +#include "util/perf/u_perfetto.h" #include "macros.h" @@ -44,9 +45,34 @@ util_get_current_cpu(void) #endif } +struct u_thread_param { + int (*routine)(void *); + void *arg; +}; + +static int +thread_routine(void *arg) +{ + struct u_thread_param *paramp = arg; + struct u_thread_param param = *paramp; + + free(paramp); + + int ret = param.routine(param.arg); + + util_perfetto_thread_flush(); + + return ret; +} + int u_thread_create(thrd_t *thrd, int (*routine)(void *), void *param) { + struct u_thread_param *paramp = malloc(sizeof(*paramp)); int ret = thrd_error; + + paramp->routine = routine; + paramp->arg = param; + #if defined(HAVE_PTHREAD) && !DETECT_OS_FUCHIA sigset_t saved_set, new_set; @@ -59,10 +85,10 @@ int u_thread_create(thrd_t *thrd, int (*routine)(void *), void *param) */ sigdelset(&new_set, SIGSEGV); pthread_sigmask(SIG_BLOCK, &new_set, &saved_set); - ret = thrd_create(thrd, routine, param); + ret = thrd_create(thrd, thread_routine, paramp); pthread_sigmask(SIG_SETMASK, &saved_set, NULL); #else - ret = thrd_create(thrd, routine, param); + ret = thrd_create(thrd, thread_routine, paramp); #endif return ret;