From 4ab9d32bd3b51908a6b55f7de2641e19fe749f76 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Mon, 26 Sep 2016 09:39:27 +0300 Subject: [PATCH] unified: Don't assert if work is pending on submit This makes k_work_submit to allow resubmits when the work is pending so the user code don't have to check the pending flag to avoid a possible assert. Change-Id: Ic39f3dc5936837ce84ad028cf3d426d0558c2925 Signed-off-by: Luiz Augusto von Dentz --- include/kernel.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/include/kernel.h b/include/kernel.h index 9303159c09a..bc3d4bcd40a 100644 --- a/include/kernel.h +++ b/include/kernel.h @@ -512,13 +512,23 @@ static inline void k_work_init(struct k_work *work, k_work_handler_t handler) /** * @brief Submit a work item to a workqueue. + * + * This procedure schedules a work item to be processed. + * In the case where the work item has already been submitted and is pending + * execution, calling this function will result in a no-op. In this case, the + * work item must not be modified externally (e.g. by the caller of this + * function), since that could cause the work item to be processed in a + * corrupted state. + * + * @param work_q to schedule the work item + * @param work work item + * + * @return N/A */ static inline void k_work_submit_to_queue(struct k_work_q *work_q, struct k_work *work) { - if (atomic_test_and_set_bit(work->flags, K_WORK_STATE_PENDING)) { - __ASSERT_NO_MSG(0); - } else { + if (!atomic_test_and_set_bit(work->flags, K_WORK_STATE_PENDING)) { k_fifo_put(&work_q->fifo, work); } }