From 482579e491872805922c6f6a74cca8b42ab77226 Mon Sep 17 00:00:00 2001 From: Niranjhana N Date: Mon, 24 Sep 2018 13:24:52 +0530 Subject: [PATCH] lib: posix: add error code return Added return of ESRCH error code in pthread_getschedparam() when the specified thread could not be found. Signed-off-by: Niranjhana N --- lib/posix/pthread.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/posix/pthread.c b/lib/posix/pthread.c index 7cd773298ee5b6..3fbfcd6dab0a75 100644 --- a/lib/posix/pthread.c +++ b/lib/posix/pthread.c @@ -296,8 +296,14 @@ int pthread_attr_init(pthread_attr_t *attr) int pthread_getschedparam(pthread_t pthread, int *policy, struct sched_param *param) { - k_tid_t thread = (k_tid_t)pthread; - u32_t priority = k_thread_priority_get(thread); + struct posix_thread *thread = (struct posix_thread *) pthread; + u32_t priority; + + if (thread == NULL || thread->state == PTHREAD_TERMINATED) { + return ESRCH; + } + + priority = k_thread_priority_get((k_tid_t) thread); param->priority = zephyr_to_posix_priority(priority, policy); return 0;