Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

options/posix: Fix function prototype of pthread_exit #933

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions options/posix/generic/pthread-stubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion options/posix/include/pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading