Hide ThreadResult.pointer usages

This commit is contained in:
Vftdan 2024-10-25 15:33:58 +02:00
parent a3f00a7b22
commit 1120424949
3 changed files with 14 additions and 6 deletions

View File

@ -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;
/**

View File

@ -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

View File

@ -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);