Skip to content

Commit

Permalink
posix: rename priority in sched_param struct
Browse files Browse the repository at this point in the history
Priority member in the sched_param struct should be named
sched_priority.

Fixes zephyrproject-rtos#13470

Signed-off-by: Anas Nashif <[email protected]>
  • Loading branch information
nashif committed Feb 19, 2019
1 parent 40b63e5 commit 04743c9
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion include/posix/posix_sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extern "C" {
#endif /* SCHED_RR */

struct sched_param {
int priority;
int sched_priority;
};

/**
Expand Down
8 changes: 4 additions & 4 deletions lib/posix/pthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static s32_t posix_to_zephyr_priority(u32_t priority, int policy)
int pthread_attr_setschedparam(pthread_attr_t *attr,
const struct sched_param *schedparam)
{
int priority = schedparam->priority;
int priority = schedparam->sched_priority;

if ((attr == NULL) || (attr->initialized == 0) ||
(is_posix_prio_valid(priority, attr->schedpolicy) == false)) {
Expand Down Expand Up @@ -262,7 +262,7 @@ int pthread_setschedparam(pthread_t pthread, int policy,
return EINVAL;
}

new_prio = posix_to_zephyr_priority(param->priority, policy);
new_prio = posix_to_zephyr_priority(param->sched_priority, policy);

if (is_posix_prio_valid(new_prio, policy) == false) {
return EINVAL;
Expand Down Expand Up @@ -306,7 +306,7 @@ int pthread_getschedparam(pthread_t pthread, int *policy,

priority = k_thread_priority_get((k_tid_t) thread);

param->priority = zephyr_to_posix_priority(priority, policy);
param->sched_priority = zephyr_to_posix_priority(priority, policy);
return 0;
}

Expand Down Expand Up @@ -564,7 +564,7 @@ int pthread_attr_getschedparam(const pthread_attr_t *attr,
return EINVAL;
}

schedparam->priority = attr->priority;
schedparam->sched_priority = attr->priority;
return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/posix/common/src/mutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void test_posix_normal_mutex(void)
int schedpolicy = SCHED_FIFO;
int ret, type, protocol, temp;

schedparam.priority = 2;
schedparam.sched_priority = 2;
ret = pthread_attr_init(&attr);
if (ret != 0) {
zassert_false(pthread_attr_destroy(&attr),
Expand Down Expand Up @@ -126,7 +126,7 @@ void test_posix_recursive_mutex(void)
int schedpolicy = SCHED_FIFO;
int ret, type, protocol, temp;

schedparam2.priority = 2;
schedparam2.sched_priority = 2;
ret = pthread_attr_init(&attr2);
if (ret != 0) {
zassert_false(pthread_attr_destroy(&attr2),
Expand Down
4 changes: 2 additions & 2 deletions tests/posix/common/src/posix_rwlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static void *thread_top(void *p1)
pthread = (pthread_t) pthread_self();
pthread_getschedparam(pthread, &policy, &param);
printk("Thread %d scheduling policy = %d & priority %d started\n",
(s32_t) p1, policy, param.priority);
(s32_t) p1, policy, param.sched_priority);

ret = pthread_rwlock_tryrdlock(&rwlock);
if (ret) {
Expand Down Expand Up @@ -84,7 +84,7 @@ void test_posix_rw_lock(void)
"Unable to create pthread object attrib");

/* Setting scheduling priority */
schedparam.priority = i + 1;
schedparam.sched_priority = i + 1;
pthread_attr_setschedparam(&attr[i], &schedparam);

/* Setting stack */
Expand Down
21 changes: 11 additions & 10 deletions tests/posix/common/src/pthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void *thread_top_exec(void *p1)

pthread_getschedparam(pthread_self(), &policy, &schedparam);
printk("Thread %d starting with scheduling policy %d & priority %d\n",
id, policy, schedparam.priority);
id, policy, schedparam.sched_priority);
/* Try a double-lock here to exercise the failing case of
* trylock. We don't support RECURSIVE locks, so this is
* guaranteed to fail.
Expand Down Expand Up @@ -187,7 +187,7 @@ void *thread_top_term(void *p1)
int val = (u32_t) p1;
struct sched_param param, getschedparam;

param.priority = N_THR_T - (s32_t) p1;
param.sched_priority = N_THR_T - (s32_t) p1;

self = pthread_self();

Expand All @@ -199,7 +199,7 @@ void *thread_top_term(void *p1)
"Unable to get thread priority!");

printk("Thread %d starting with a priority of %d\n", (s32_t) p1,
getschedparam.priority);
getschedparam.sched_priority);

if (val % 2) {
ret = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);
Expand Down Expand Up @@ -233,13 +233,13 @@ void test_posix_pthread_execution(void)
size_t stacksize;

sem_init(&main_sem, 0, 1);
schedparam.priority = CONFIG_NUM_COOP_PRIORITIES - 1;
schedparam.sched_priority = CONFIG_NUM_COOP_PRIORITIES - 1;
min_prio = sched_get_priority_min(schedpolicy);
max_prio = sched_get_priority_max(schedpolicy);

ret = (min_prio < 0 || max_prio < 0 ||
schedparam.priority < min_prio ||
schedparam.priority > max_prio);
schedparam.sched_priority < min_prio ||
schedparam.sched_priority > max_prio);

/* TESTPOINT: Check if scheduling priority is valid */
zassert_false(ret,
Expand Down Expand Up @@ -310,8 +310,9 @@ void test_posix_pthread_execution(void)

pthread_attr_setschedparam(&attr[i], &schedparam);
pthread_attr_getschedparam(&attr[i], &getschedparam);
zassert_equal(schedparam.priority, getschedparam.priority,
"scheduling priorities do not match!");
zassert_equal(schedparam.sched_priority,
getschedparam.sched_priority,
"scheduling priorities do not match!");

ret = pthread_create(&newthread[i], &attr[i], thread_top_exec,
(void *)i);
Expand Down Expand Up @@ -372,7 +373,7 @@ void test_posix_pthread_termination(void)
PTHREAD_CREATE_DETACHED);
}

schedparam.priority = 2;
schedparam.sched_priority = 2;
pthread_attr_setschedparam(&attr[i], &schedparam);
pthread_attr_setstack(&attr[i], &stack_t[i][0], STACKS);
ret = pthread_create(&newthread[i], &attr[i], thread_top_term,
Expand All @@ -390,7 +391,7 @@ void test_posix_pthread_termination(void)
zassert_equal(ret, EINVAL, "invalid policy set!");

/* TESTPOINT: Try setting invalid priority */
schedparam.priority = PRIO_INVALID;
schedparam.sched_priority = PRIO_INVALID;
ret = pthread_setschedparam(newthread[0], SCHED_RR, &schedparam);
zassert_equal(ret, EINVAL, "invalid priority set!");

Expand Down
4 changes: 2 additions & 2 deletions tests/posix/common/src/pthread_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void test_posix_multiple_threads_single_key(void)
"Unable to create pthread object attr");
}

schedparam.priority = 2;
schedparam.sched_priority = 2;
pthread_attr_setschedparam(&attr[i], &schedparam);
pthread_attr_setstack(&attr[i], &stackp[i][0], STACKSZ);

Expand Down Expand Up @@ -188,7 +188,7 @@ void test_posix_single_thread_multiple_keys(void)
"Unable to create pthread object attr");
}

schedparam.priority = 2;
schedparam.sched_priority = 2;
pthread_attr_setschedparam(&attr, &schedparam);
pthread_attr_setstack(&attr, &stackp[0][0], STACKSZ);

Expand Down
2 changes: 1 addition & 1 deletion tests/posix/common/src/semaphore.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void initialize_thread_attr(pthread_attr_t *attr)
{
int ret;

schedparam.priority = 1;
schedparam.sched_priority = 1;

ret = pthread_attr_init(attr);
if (ret != 0) {
Expand Down

0 comments on commit 04743c9

Please sign in to comment.