From 08b8c5ce8462d599388a7272b5345c4ec80f36d7 Mon Sep 17 00:00:00 2001 From: Dennis Bonke Date: Mon, 23 Oct 2023 20:04:00 +0200 Subject: [PATCH] options/posix: Fix function prototype of pthread_exit --- options/posix/generic/pthread-stubs.cpp | 14 ++++++++++---- options/posix/include/pthread.h | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/options/posix/generic/pthread-stubs.cpp b/options/posix/generic/pthread-stubs.cpp index f9eed3b366..b7f5fc666f 100644 --- a/options/posix/generic/pthread-stubs.cpp +++ b/options/posix/generic/pthread-stubs.cpp @@ -354,11 +354,18 @@ namespace { FutexLock key_mutex_; } -int pthread_exit(void *ret_val) { +namespace mlibc { + __attribute__ ((__noreturn__)) void do_exit() { + sys_thread_exit(); + __builtin_unreachable(); + } +} + +__attribute__ ((__noreturn__)) void pthread_exit(void *ret_val) { auto self = mlibc::get_current_tcb(); if (__atomic_load_n(&self->cancelBits, __ATOMIC_RELAXED) & tcbExitingBit) - return 0; // We are already exiting + mlibc::do_exit(); __atomic_fetch_or(&self->cancelBits, tcbExitingBit, __ATOMIC_RELAXED); @@ -392,8 +399,7 @@ int pthread_exit(void *ret_val) { // TODO: clean up thread resources when we are detached. // TODO: do exit(0) when we're the only thread instead - mlibc::sys_thread_exit(); - __builtin_unreachable(); + mlibc::do_exit(); } int pthread_join(pthread_t thread, void **ret) { diff --git a/options/posix/include/pthread.h b/options/posix/include/pthread.h index b93ca8dcb8..739f60798f 100644 --- a/options/posix/include/pthread.h +++ b/options/posix/include/pthread.h @@ -180,7 +180,7 @@ int pthread_create(pthread_t *__restrict, const pthread_attr_t *__restrict, void *(*) (void *), void *__restrict); pthread_t pthread_self(void); int pthread_equal(pthread_t, pthread_t); -int pthread_exit(void *); +__attribute__ ((__noreturn__)) void pthread_exit(void *); int pthread_join(pthread_t, void **); int pthread_detach(pthread_t);