mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-02-21 01:07:18 +08:00
[DeviceDrivers] Add critical_work for wqueue.
This commit is contained in:
parent
385792bb68
commit
b4757b950f
@ -86,6 +86,28 @@ rt_err_t rt_workqueue_dowork(struct rt_workqueue* queue, struct rt_work* work)
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
rt_err_t rt_workqueue_critical_work(struct rt_workqueue* queue, struct rt_work* work)
|
||||
{
|
||||
RT_ASSERT(queue != RT_NULL);
|
||||
RT_ASSERT(work != RT_NULL);
|
||||
|
||||
rt_enter_critical();
|
||||
/* NOTE: the work MUST be initialized firstly */
|
||||
rt_list_remove(&(work->list));
|
||||
|
||||
rt_list_insert_after(queue->work_list.prev, &(work->list));
|
||||
if (queue->work_thread->stat != RT_THREAD_READY)
|
||||
{
|
||||
rt_exit_critical();
|
||||
/* resume work thread */
|
||||
rt_thread_resume(queue->work_thread);
|
||||
rt_schedule();
|
||||
}
|
||||
else rt_exit_critical();
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
rt_err_t rt_workqueue_cancel_work(struct rt_workqueue* queue, struct rt_work* work)
|
||||
{
|
||||
RT_ASSERT(queue != RT_NULL);
|
||||
@ -98,5 +120,21 @@ rt_err_t rt_workqueue_cancel_work(struct rt_workqueue* queue, struct rt_work* wo
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
rt_err_t rt_workqueue_cancel_all_work(struct rt_workqueue* queue)
|
||||
{
|
||||
struct rt_list_node *node, *next;
|
||||
RT_ASSERT(queue != RT_NULL);
|
||||
|
||||
rt_enter_critical();
|
||||
for (node = queue->work_list.next; node != &(queue->work_list); node = next)
|
||||
{
|
||||
next = node->next;
|
||||
rt_list_remove(node);
|
||||
}
|
||||
rt_exit_critical();
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user