From eaab7f567216891fa0eb8b1960888b603d5f973b Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 7 Dec 2019 14:33:18 +0100 Subject: [PATCH] LibPthread: Don't set errno in pthread functions POSIX says that pthread API's don't set errno directly. If there is an error, it should be the return value from the function instead. --- Libraries/LibPthread/pthread.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Libraries/LibPthread/pthread.cpp b/Libraries/LibPthread/pthread.cpp index 8c35406dc1b..6e43fe1281e 100644 --- a/Libraries/LibPthread/pthread.cpp +++ b/Libraries/LibPthread/pthread.cpp @@ -24,8 +24,7 @@ extern "C" { static int create_thread(void* (*entry)(void*), void* argument, void* stack) { - int rc = syscall(SC_create_thread, entry, argument, stack); - __RETURN_WITH_ERRNO(rc, rc, -1); + return syscall(SC_create_thread, entry, argument, stack); } static void exit_thread(void* code) @@ -83,8 +82,7 @@ void pthread_exit(void* value_ptr) int pthread_join(pthread_t thread, void** exit_value_ptr) { - int rc = syscall(SC_join_thread, thread, exit_value_ptr); - __RETURN_WITH_ERRNO(rc, rc, -1); + return syscall(SC_join_thread, thread, exit_value_ptr); } int pthread_mutex_init(pthread_mutex_t* mutex, const pthread_mutexattr_t* attributes) @@ -413,10 +411,9 @@ int pthread_cond_timedwait(pthread_cond_t* cond, pthread_mutex_t* mutex, const s while (node.waiting) { struct timespec now; if (clock_gettime(condvar.clock, &now) < 0) - return -1; + return errno; if ((abstime->tv_sec < now.tv_sec) || (abstime->tv_sec == now.tv_sec && abstime->tv_nsec <= now.tv_nsec)) { - errno = ETIMEDOUT; - return -1; + return ETIMEDOUT; } pthread_mutex_unlock(mutex); sched_yield();