kernel/sched: refactor _get_first_thread_to_unpend()

Modify _get_first_thread_to_unpend() so that it does not remove the
thread from the wait queue. Rename it to _find_first_thread_to_unpend()
to match the new behaviour.

This will be needed to fix a semaphore group bug.

Change-Id: I1b7531c3beecf3b6a86ecf88a93a02449edd0767
Signed-off-by: Benjamin Walsh <walsh.benj@gmail.com>
This commit is contained in:
Benjamin Walsh 2017-02-12 09:41:29 -05:00 committed by Anas Nashif
commit cf93743f50

View file

@ -440,44 +440,34 @@ static inline struct k_thread *_peek_first_pending_thread(_wait_q_t *wait_q)
return (struct k_thread *)sys_dlist_peek_head(wait_q);
}
static inline struct k_thread *_get_thread_to_unpend(_wait_q_t *wait_q)
static inline struct k_thread *
_find_first_thread_to_unpend(_wait_q_t *wait_q, struct k_thread *from)
{
#ifdef CONFIG_SYS_CLOCK_EXISTS
extern volatile int _handling_timeouts;
if (_handling_timeouts) {
sys_dlist_t *q = (sys_dlist_t *)wait_q;
sys_dnode_t *cur, *next;
sys_dnode_t *cur = from ? &from->base.k_q_node : NULL;
/* skip threads that have an expired timeout */
SYS_DLIST_FOR_EACH_NODE_SAFE(q, cur, next) {
SYS_DLIST_ITERATE_FROM_NODE(q, cur) {
struct k_thread *thread = (struct k_thread *)cur;
if (_is_thread_timeout_expired(thread)) {
continue;
}
sys_dlist_remove(cur);
return thread;
}
return NULL;
}
#else
ARG_UNUSED(from);
#endif
return (struct k_thread *)sys_dlist_get(wait_q);
}
return (struct k_thread *)sys_dlist_peek_head(wait_q);
/* unpend the first thread from a wait queue */
/* must be called with interrupts locked */
static inline struct k_thread *_unpend_first_thread(_wait_q_t *wait_q)
{
struct k_thread *thread = _get_thread_to_unpend(wait_q);
if (thread) {
_mark_thread_as_not_pending(thread);
}
return thread;
}
/* Unpend a thread from the wait queue it is on. Thread must be pending. */
@ -490,4 +480,17 @@ static inline void _unpend_thread(struct k_thread *thread)
_mark_thread_as_not_pending(thread);
}
/* unpend the first thread from a wait queue */
/* must be called with interrupts locked */
static inline struct k_thread *_unpend_first_thread(_wait_q_t *wait_q)
{
struct k_thread *thread = _find_first_thread_to_unpend(wait_q, NULL);
if (thread) {
_unpend_thread(thread);
}
return thread;
}
#endif /* _ksched__h_ */