tests/posix/common: restructure to eliminate casts
Restructure code to reduce the number of obnoxious casts. Signed-off-by: Charles E. Youse <charles.youse@intel.com>
This commit is contained in:
parent
dc0314af7f
commit
f914669075
|
@ -19,11 +19,12 @@ static void *thread_top(void *p1)
|
|||
pthread_t pthread;
|
||||
u32_t policy, ret = 0U;
|
||||
struct sched_param param;
|
||||
int id = POINTER_TO_INT(p1);
|
||||
|
||||
pthread = (pthread_t) pthread_self();
|
||||
pthread_getschedparam(pthread, &policy, ¶m);
|
||||
printk("Thread %d scheduling policy = %d & priority %d started\n",
|
||||
(int) POINTER_TO_INT(p1), policy, param.sched_priority);
|
||||
id, policy, param.sched_priority);
|
||||
|
||||
ret = pthread_rwlock_tryrdlock(&rwlock);
|
||||
if (ret) {
|
||||
|
@ -32,21 +33,21 @@ static void *thread_top(void *p1)
|
|||
"Failed to acquire write lock");
|
||||
}
|
||||
|
||||
printk("Thread %d got RD lock\n", (int) POINTER_TO_INT(p1));
|
||||
printk("Thread %d got RD lock\n", id);
|
||||
usleep(USEC_PER_MSEC);
|
||||
printk("Thread %d releasing RD lock\n", (int) POINTER_TO_INT(p1));
|
||||
printk("Thread %d releasing RD lock\n", id);
|
||||
zassert_false(pthread_rwlock_unlock(&rwlock), "Failed to unlock");
|
||||
|
||||
printk("Thread %d acquiring WR lock\n", (int) POINTER_TO_INT(p1));
|
||||
printk("Thread %d acquiring WR lock\n", id);
|
||||
ret = pthread_rwlock_trywrlock(&rwlock);
|
||||
if (ret != 0U) {
|
||||
zassert_false(pthread_rwlock_wrlock(&rwlock),
|
||||
"Failed to acquire WR lock");
|
||||
}
|
||||
|
||||
printk("Thread %d acquired WR lock\n", (int) POINTER_TO_INT(p1));
|
||||
printk("Thread %d acquired WR lock\n", id);
|
||||
usleep(USEC_PER_MSEC);
|
||||
printk("Thread %d releasing WR lock\n", (int) POINTER_TO_INT(p1));
|
||||
printk("Thread %d releasing WR lock\n", id);
|
||||
zassert_false(pthread_rwlock_unlock(&rwlock), "Failed to unlock");
|
||||
pthread_exit(NULL);
|
||||
return NULL;
|
||||
|
|
|
@ -186,10 +186,10 @@ void *thread_top_term(void *p1)
|
|||
{
|
||||
pthread_t self;
|
||||
int oldstate, policy, ret;
|
||||
int val = (u32_t) POINTER_TO_INT(p1);
|
||||
int id = POINTER_TO_INT(p1);
|
||||
struct sched_param param, getschedparam;
|
||||
|
||||
param.sched_priority = N_THR_T - (s32_t) POINTER_TO_INT(p1);
|
||||
param.sched_priority = N_THR_T - id;
|
||||
|
||||
self = pthread_self();
|
||||
|
||||
|
@ -201,25 +201,24 @@ void *thread_top_term(void *p1)
|
|||
"Unable to get thread priority!");
|
||||
|
||||
printk("Thread %d starting with a priority of %d\n",
|
||||
(s32_t) POINTER_TO_INT(p1),
|
||||
id,
|
||||
getschedparam.sched_priority);
|
||||
|
||||
if (val % 2) {
|
||||
if (id % 2) {
|
||||
ret = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);
|
||||
zassert_false(ret, "Unable to set cancel state!");
|
||||
}
|
||||
|
||||
if (val >= 2) {
|
||||
if (id >= 2) {
|
||||
ret = pthread_detach(self);
|
||||
if (val == 2) {
|
||||
if (id == 2) {
|
||||
zassert_equal(ret, EINVAL, "re-detached thread!");
|
||||
}
|
||||
}
|
||||
|
||||
printk("Cancelling thread %d\n", (s32_t) POINTER_TO_INT(p1));
|
||||
printk("Cancelling thread %d\n", id);
|
||||
pthread_cancel(self);
|
||||
printk("Thread %d could not be cancelled\n",
|
||||
(s32_t) POINTER_TO_INT(p1));
|
||||
printk("Thread %d could not be cancelled\n", id);
|
||||
sleep(ONE_SECOND);
|
||||
pthread_exit(p1);
|
||||
return NULL;
|
||||
|
|
Loading…
Reference in a new issue