From f2d3cc7325c6c75b7ceff55c030c22ac89e3ce4d Mon Sep 17 00:00:00 2001 From: Muhammad Zahalqa Date: Sat, 18 Jul 2020 22:35:12 +0300 Subject: [PATCH] LibPThread: Make pthread_exit a noreturn function LibPThread: mark pthread_exit a noreturn function using compiler attributes LibThread: remove a call to pthread_exit from Thread::start lambda expression as it make the return of teh lambda unreachable. --- Libraries/LibPthread/pthread.cpp | 1 + Libraries/LibPthread/pthread.h | 2 +- Libraries/LibThread/Thread.cpp | 3 +-- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Libraries/LibPthread/pthread.cpp b/Libraries/LibPthread/pthread.cpp index e90e8a7399..f3a17849b6 100644 --- a/Libraries/LibPthread/pthread.cpp +++ b/Libraries/LibPthread/pthread.cpp @@ -83,6 +83,7 @@ static int create_thread(void* (*entry)(void*), void* argument, PthreadAttrImpl* return syscall(SC_create_thread, pthread_create_helper, thread_params); } +[[noreturn]] static void exit_thread(void* code) { syscall(SC_exit_thread, code); diff --git a/Libraries/LibPthread/pthread.h b/Libraries/LibPthread/pthread.h index 6fbb7453bb..1f71b911b8 100644 --- a/Libraries/LibPthread/pthread.h +++ b/Libraries/LibPthread/pthread.h @@ -35,7 +35,7 @@ __BEGIN_DECLS int pthread_create(pthread_t*, pthread_attr_t*, void* (*)(void*), void*); -void pthread_exit(void*); +void pthread_exit(void*) __attribute__ ((noreturn)); int pthread_kill(pthread_t, int); void pthread_cleanup_push(void (*)(void*), void*); void pthread_cleanup_pop(int); diff --git a/Libraries/LibThread/Thread.cpp b/Libraries/LibThread/Thread.cpp index 94b5bcd502..7828627d30 100644 --- a/Libraries/LibThread/Thread.cpp +++ b/Libraries/LibThread/Thread.cpp @@ -51,8 +51,7 @@ void LibThread::Thread::start() [](void* arg) -> void* { Thread* self = static_cast(arg); size_t exit_code = self->m_action(); - self->m_tid = 0; - pthread_exit((void*)exit_code); + self->m_tid = 0; return (void*)exit_code; }, static_cast(this));