kernel: Fix sloppy wait queue API

There were multiple spots where code was using the _wait_q_t
abstraction as a synonym for a dlist and doing direct list management
on them with the dlist APIs.  Refactor _wait_q_t into a proper opaque
struct (not a typedef for sys_dlist_t) and write a simple wrapper API
for the existing usages.  Now replacement of wait_q with a different
data structure is much cleaner.

Note that there were some SYS_DLIST_FOR_EACH_SAFE loops in mailbox.c
that got replaced by the normal/non-safe macro.  While these loops do
mutate the list in the code body, they always do an early return in
those circumstances instead of returning into the macro'd for() loop,
so the _SAFE usage was needless.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
This commit is contained in:
Andy Ross 2018-05-10 11:10:34 -07:00 committed by Anas Nashif
commit ccf3bf7ed3
18 changed files with 71 additions and 56 deletions

View file

@ -8,6 +8,7 @@
#define __PTHREAD_H__
#include <kernel.h>
#include <wait_q.h>
#include <posix/time.h>
#include <posix/unistd.h>
#include "sys/types.h"
@ -63,7 +64,7 @@ struct posix_thread {
*/
#define PTHREAD_COND_DEFINE(name) \
struct pthread_cond name = { \
.wait_q = SYS_DLIST_STATIC_INIT(&name.wait_q), \
.wait_q = _WAIT_Q_INIT(&name.wait_q), \
}
/**
@ -75,7 +76,7 @@ static inline int pthread_cond_init(pthread_cond_t *cv,
const pthread_condattr_t *att)
{
ARG_UNUSED(att);
sys_dlist_init(&cv->wait_q);
_waitq_init(&cv->wait_q);
return 0;
}
@ -284,7 +285,7 @@ static inline int pthread_mutexattr_destroy(pthread_mutexattr_t *m)
*/
#define PTHREAD_BARRIER_DEFINE(name, count) \
struct pthread_barrier name = { \
.wait_q = SYS_DLIST_STATIC_INIT(&name.wait_q), \
.wait_q = _WAIT_Q_INIT(&name.wait_q), \
.max = count, \
}
@ -308,7 +309,7 @@ static inline int pthread_barrier_init(pthread_barrier_t *b,
b->max = count;
b->count = 0;
sys_dlist_init(&b->wait_q);
_waitq_init(&b->wait_q);
return 0;
}