From 11204249496e81f5ae09e7e0140783bce764e209 Mon Sep 17 00:00:00 2001 From: Vftdan Date: Fri, 25 Oct 2024 15:33:58 +0200 Subject: [PATCH] Hide ThreadResult.pointer usages --- src/common/util/thread.h | 10 +++++++++- src/common/util/thread.posix.c | 8 ++++---- src/common/util/thread.std.c | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/common/util/thread.h b/src/common/util/thread.h index 3497b89..6655429 100644 --- a/src/common/util/thread.h +++ b/src/common/util/thread.h @@ -11,11 +11,19 @@ typedef union { typedef union { uint32_t value; - void *pointer; // Bits outside of .value may be reset + void *_pointer; // Bits outside of .value may be reset } ThreadResult; #define THREAD_NONE (Thread) { .handle = 0, } +HEADER_FN ThreadResult +thread_wrap_result(uint32_t value) +{ + ThreadResult res = { ._pointer = NULL }; + res.value = value; + return res; +} + typedef CLOSURE_T(ThreadResult) ThreadEntry; /** diff --git a/src/common/util/thread.posix.c b/src/common/util/thread.posix.c index 249da04..69d2322 100644 --- a/src/common/util/thread.posix.c +++ b/src/common/util/thread.posix.c @@ -53,13 +53,13 @@ run_entry(void *arg) assert(arg != NULL); NativeEntryArg casted_arg = *(NativeEntryArg*) arg; ThreadEntry entry = casted_arg.entry; - void *error_result = casted_arg.error_result.pointer; + void *error_result = casted_arg.error_result._pointer; free(arg); if (!entry.callback) { return error_result; } ThreadResult result = entry.callback(entry.env); - return result.pointer; + return result._pointer; } Thread @@ -106,7 +106,7 @@ thread_join(Thread th, ThreadResult *result_ptr) pthread_t handle = get_handle(th); void **retval = NULL; if (result_ptr) { - retval = &result_ptr->pointer; + retval = &result_ptr->_pointer; } int error = pthread_join(handle, retval); if (error) { @@ -119,7 +119,7 @@ thread_join(Thread th, ThreadResult *result_ptr) void thread_exit(ThreadResult result) { - pthread_exit(result.pointer); + pthread_exit(result._pointer); } bool diff --git a/src/common/util/thread.std.c b/src/common/util/thread.std.c index 1198611..46dfaa4 100644 --- a/src/common/util/thread.std.c +++ b/src/common/util/thread.std.c @@ -111,7 +111,7 @@ thread_join(Thread th, ThreadResult *result_ptr) thrd_t handle = get_handle(th); int32_t *retval = NULL; if (result_ptr) { - result_ptr->pointer = NULL; + *result_ptr = thread_wrap_result(0); retval = (int32_t*) &result_ptr->value; } int error = thrd_join(handle, retval);