Skip to content

Commit

Permalink
unified: Simplify k_msgq_purge()
Browse files Browse the repository at this point in the history
Simplifies k_msgq_purge() at the expense of making the case of an
already empty message queue a little slower.

Change-Id: I8fafd6d49233efbf23b95d171f81bf795e828454
Signed-off-by: Peter Mitsis <[email protected]>
  • Loading branch information
wrsPeterMitsis authored and benwrs committed Oct 4, 2016
1 parent 223b962 commit 340d00a
Showing 1 changed file with 10 additions and 24 deletions.
34 changes: 10 additions & 24 deletions kernel/unified/msg_q.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,31 +186,17 @@ int k_msgq_get(struct k_msgq *q, void *data, int32_t timeout)
void k_msgq_purge(struct k_msgq *q)
{
unsigned int key = irq_lock();
struct tcs *pending_thread;

if (q->used_msgs) {
/* wake up any threads that are waiting to write */
while (1) {
struct tcs *pending_thread =
_unpend_first_thread(&q->wait_q);

if (pending_thread == NULL) {
break;
}
_set_thread_return_value(pending_thread, -ENOMSG);
_timeout_abort(pending_thread);
_ready_thread(pending_thread);
}

q->used_msgs = 0;
q->read_ptr = q->write_ptr;

if (_must_switch_threads()) {
_Swap(key);
return;
}
} else {
/* queue is empty, so no need to do anything ... */
/* wake up any threads that are waiting to write */
while ((pending_thread = _unpend_first_thread(&q->wait_q)) != NULL) {
_set_thread_return_value(pending_thread, -ENOMSG);
_timeout_abort(pending_thread);
_ready_thread(pending_thread);
}

irq_unlock(key);
q->used_msgs = 0;
q->read_ptr = q->write_ptr;

_reschedule_threads(key);
}

0 comments on commit 340d00a

Please sign in to comment.