From 558ed8fd4458f4ca3e7aa922ff755875deb32845 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 21 Apr 2026 00:25:16 +0300 Subject: [PATCH] LibC: Define pthread_{equal,self} as macros These really should get inlined :D --- userspace/libraries/LibC/include/pthread.h | 6 ++++++ userspace/libraries/LibC/pthread.cpp | 25 +++++++++++----------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/userspace/libraries/LibC/include/pthread.h b/userspace/libraries/LibC/include/pthread.h index d35acadc..89e1dcbc 100644 --- a/userspace/libraries/LibC/include/pthread.h +++ b/userspace/libraries/LibC/include/pthread.h @@ -169,6 +169,12 @@ void pthread_testcancel(void); void pthread_cleanup_pop(int execute); void pthread_cleanup_push(void (*routine)(void*), void* arg); +#define _pthread_equal(t1, t2) ((t1) == (t2)) +#define pthread_equal(t1, t2) _pthread_equal(t1, t2) + +#define _pthread_self() (_get_uthread()->id) +#define pthread_self() _pthread_self() + #define _pthread_testcancel() do { \ struct uthread* uthread = _get_uthread(); \ if (__builtin_expect(uthread->cancel_state == PTHREAD_CANCEL_ENABLE, 1)) \ diff --git a/userspace/libraries/LibC/pthread.cpp b/userspace/libraries/LibC/pthread.cpp index 2768364c..3f3aeefa 100644 --- a/userspace/libraries/LibC/pthread.cpp +++ b/userspace/libraries/LibC/pthread.cpp @@ -489,29 +489,29 @@ void pthread_exit(void* value_ptr) ASSERT_NOT_REACHED(); } +#undef pthread_equal int pthread_equal(pthread_t t1, pthread_t t2) { - return t1 == t2; + return _pthread_equal(t1, t2); } +#define pthread_equal(t1, t2) _pthread_equal(t1, t2) + +#undef pthread_self +pthread_t pthread_self(void) +{ + return _pthread_self(); +} +#define pthread_self() _pthread_self() int pthread_join(pthread_t thread, void** value_ptr) { - pthread_testcancel(); - - errno = 0; - while (syscall(SYS_PTHREAD_JOIN, thread, value_ptr) == -1 && errno == EINTR) - { + do { pthread_testcancel(); errno = 0; - } + } while (syscall(SYS_PTHREAD_JOIN, thread, value_ptr) == -1 && errno == EINTR); return errno; } -pthread_t pthread_self(void) -{ - return _get_uthread()->id; -} - int pthread_once(pthread_once_t* once_control, void (*init_routine)(void)) { static_assert(PTHREAD_ONCE_INIT == 0); @@ -671,6 +671,7 @@ void pthread_testcancel(void) { _pthread_testcancel(); } +#define pthread_testcancel() _pthread_testcancel() int pthread_getschedparam(pthread_t thread, int* __restrict policy, struct sched_param* __restrict param) {