From 10563a5fb2e9f18ef9a9669cda202f5a275ff807 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Mon, 15 Jul 2024 21:30:23 -0400 Subject: [PATCH] pthread: Reorder the extension functions and make them non-weak. Put the extensions above the "Haiku thread API bridge", fix their indentation, and make them standard instead of weak symbols. (musl does not declare these functions as weak symbols, at least.) --- src/system/libroot/posix/pthread/pthread.cpp | 60 ++++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/system/libroot/posix/pthread/pthread.cpp b/src/system/libroot/posix/pthread/pthread.cpp index 1d392d7844..8ca7831d33 100644 --- a/src/system/libroot/posix/pthread/pthread.cpp +++ b/src/system/libroot/posix/pthread/pthread.cpp @@ -299,14 +299,42 @@ int pthread_setschedparam(pthread_t thread, int policy, const struct sched_param *param) { - status_t status; if (policy != SCHED_RR && policy != SCHED_OTHER) return ENOTSUP; if (policy == SCHED_RR && param->sched_priority < B_FIRST_REAL_TIME_PRIORITY) return EINVAL; if (policy == SCHED_OTHER && param->sched_priority >= B_FIRST_REAL_TIME_PRIORITY) return EINVAL; - status = _kern_set_thread_priority(thread->id, param->sched_priority); + + status_t status = _kern_set_thread_priority(thread->id, param->sched_priority); + if (status == B_BAD_THREAD_ID) + return ESRCH; + if (status < B_OK) + return status; + return 0; +} + + +// #pragma mark - extensions + + +int +pthread_getname_np(pthread_t thread, char* buffer, size_t length) +{ + thread_info info; + status_t status = _kern_get_thread_info(thread->id, &info); + if (status == B_BAD_THREAD_ID) + return ESRCH; + if (strlcpy(buffer, info.name, length) >= length) + return ERANGE; + return 0; +} + + +int +pthread_setname_np(pthread_t thread, const char* name) +{ + status_t status = _kern_rename_thread(thread->id, name); if (status == B_BAD_THREAD_ID) return ESRCH; if (status < B_OK) @@ -323,31 +351,3 @@ get_pthread_thread_id(pthread_t thread) { return thread->id; } - - -int -__pthread_getname_np(pthread_t thread, char* buffer, size_t length) -{ - thread_info info; - status_t status = _kern_get_thread_info(thread->id, &info); - if (status == B_BAD_THREAD_ID) - return ESRCH; - if (strlcpy(buffer, info.name, length) >= length) - return ERANGE; - return 0; -} - - -int -__pthread_setname_np(pthread_t thread, const char* name) -{ - status_t status = _kern_rename_thread(thread->id, name); - if (status == B_BAD_THREAD_ID) - return ESRCH; - if (status < B_OK) - return status; - return 0; -} - -B_DEFINE_WEAK_ALIAS(__pthread_getname_np, pthread_getname_np); -B_DEFINE_WEAK_ALIAS(__pthread_setname_np, pthread_setname_np);