Skip to content

Commit

Permalink
posix: implement pthread_setschedprio
Browse files Browse the repository at this point in the history
Implement posix pthread_setschedprio()

Signed-off-by: Gaetan Perrot <gaetanperrotpro@gmail.com>
  • Loading branch information
moonlight83340 committed Apr 3, 2024
1 parent d5b1a7d commit 1d651d1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/zephyr/posix/pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ int pthread_attr_setschedparam(pthread_attr_t *attr,
const struct sched_param *schedparam);
int pthread_setschedparam(pthread_t pthread, int policy,
const struct sched_param *param);
int pthread_setschedprio(pthread_t thread, int prio);
int pthread_rwlock_destroy(pthread_rwlock_t *rwlock);
int pthread_rwlock_init(pthread_rwlock_t *rwlock,
const pthread_rwlockattr_t *attr);
Expand Down
40 changes: 40 additions & 0 deletions lib/posix/options/pthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,46 @@ int pthread_setschedparam(pthread_t pthread, int policy, const struct sched_para
return ret;
}

/**
* @brief Set thread scheduling priority.
*
* See IEEE 1003.1
*/
int pthread_setschedprio(pthread_t thread, int prio)
{
int ret = 0;
int new_prio = K_LOWEST_APPLICATION_THREAD_PRIO;
struct posix_thread *t = NULL;
int policy = 0;
struct sched_param param;

ret = pthread_getschedparam(thread, &policy, &param);

if (ret != 0) {
return ret;
}

if (!is_posix_policy_prio_valid(prio, policy)) {
return EINVAL;
}

K_SPINLOCK(&pthread_pool_lock) {
t = to_posix_thread(thread);
if (t == NULL) {
ret = ESRCH;
K_SPINLOCK_BREAK;
}

new_prio = posix_to_zephyr_priority(prio, policy);
}

if (ret == 0) {
k_thread_priority_set(&t->thread, new_prio);
}

return ret;
}

/**
* @brief Initialise threads attribute object
*
Expand Down

0 comments on commit 1d651d1

Please sign in to comment.