unified: Add k_work_pending
This adds k_work_pending which can be use to check if a k_work is pending execution. Change-Id: Ifd56e8d65d555c7e9722c547fe83e13e886d63cd Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
parent
62df15d598
commit
ee1e99b3b7
2 changed files with 16 additions and 7 deletions
|
@ -479,7 +479,7 @@ struct k_work_q {
|
|||
* @brief Work flags.
|
||||
*/
|
||||
enum {
|
||||
K_WORK_STATE_IDLE, /* Work item idle state */
|
||||
NANO_WORK_STATE_PENDING, /* Work item pending state */
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -498,7 +498,7 @@ struct k_work {
|
|||
{ \
|
||||
._reserved = NULL, \
|
||||
.handler = work_handler, \
|
||||
.flags = { 1 } \
|
||||
.flags = { 0 } \
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -506,7 +506,7 @@ struct k_work {
|
|||
*/
|
||||
static inline void k_work_init(struct k_work *work, k_work_handler_t handler)
|
||||
{
|
||||
atomic_set_bit(work->flags, K_WORK_STATE_IDLE);
|
||||
atomic_clear_bit(work->flags, K_WORK_STATE_PENDING);
|
||||
work->handler = handler;
|
||||
}
|
||||
|
||||
|
@ -516,13 +516,21 @@ static inline void k_work_init(struct k_work *work, k_work_handler_t handler)
|
|||
static inline void k_work_submit_to_queue(struct k_work_q *work_q,
|
||||
struct k_work *work)
|
||||
{
|
||||
if (!atomic_test_and_clear_bit(work->flags, K_WORK_STATE_IDLE)) {
|
||||
if (atomic_test_and_set_bit(work->flags, K_WORK_STATE_PENDING)) {
|
||||
__ASSERT_NO_MSG(0);
|
||||
} else {
|
||||
k_fifo_put(&work_q->fifo, work);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if work item is pending.
|
||||
*/
|
||||
static inline int k_work_pending(struct k_work *work)
|
||||
{
|
||||
return atomic_test_bit(work->flags, NANO_WORK_STATE_PENDING);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Start a new workqueue. This routine can be called from either
|
||||
* fiber or task context.
|
||||
|
|
|
@ -39,8 +39,9 @@ static void work_q_main(void *work_q_ptr, void *p2, void *p3)
|
|||
|
||||
handler = work->handler;
|
||||
|
||||
/* Set state to idle so it can be resubmitted by handler */
|
||||
if (!atomic_test_and_set_bit(work->flags, K_WORK_STATE_IDLE)) {
|
||||
/* Reset pending state so it can be resubmitted by handler */
|
||||
if (atomic_test_and_reset_bit(work->flags,
|
||||
K_WORK_STATE_PENDING)) {
|
||||
handler(work);
|
||||
}
|
||||
|
||||
|
@ -122,7 +123,7 @@ int k_delayed_work_cancel(struct k_delayed_work *work)
|
|||
{
|
||||
int key = irq_lock();
|
||||
|
||||
if (!atomic_test_bit(work->work.flags, K_WORK_STATE_IDLE)) {
|
||||
if (k_work_pending(&work->work)) {
|
||||
irq_unlock(key);
|
||||
return -EINPROGRESS;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue