posix: implement pthread_setschedprio
Implement posix pthread_setschedprio() Signed-off-by: Gaetan Perrot <gaetanperrotpro@gmail.com>
This commit is contained in:
parent
fec3cee0bb
commit
228d932967
@ -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);
|
||||
|
||||
@ -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;
|
||||
int new_prio = K_LOWEST_APPLICATION_THREAD_PRIO;
|
||||
struct posix_thread *t = NULL;
|
||||
int policy;
|
||||
struct sched_param param;
|
||||
|
||||
ret = pthread_getschedparam(thread, &policy, ¶m);
|
||||
|
||||
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
|
||||
*
|
||||
|
||||
Loading…
Reference in New Issue
Block a user