2018-10-14 19:37:18 +08:00
|
|
|
/*
|
2022-01-17 04:15:08 +08:00
|
|
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
2018-10-14 19:37:18 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
2021-08-01 16:53:26 +08:00
|
|
|
* 2021-08-01 Meco Man remove rt_delayed_work_init() and rt_delayed_work structure
|
2021-08-17 22:44:29 +08:00
|
|
|
* 2021-08-14 Jackistang add comments for rt_work_init()
|
2018-10-14 19:37:18 +08:00
|
|
|
*/
|
2017-10-15 22:56:46 +08:00
|
|
|
#ifndef WORKQUEUE_H__
|
|
|
|
#define WORKQUEUE_H__
|
|
|
|
|
|
|
|
#include <rtthread.h>
|
|
|
|
|
2022-04-02 16:21:45 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2019-03-17 16:01:12 +08:00
|
|
|
enum
|
|
|
|
{
|
2019-04-22 11:41:17 +08:00
|
|
|
RT_WORK_STATE_PENDING = 0x0001, /* Work item pending state */
|
|
|
|
RT_WORK_STATE_SUBMITTING = 0x0002, /* Work item submitting state */
|
2019-03-17 16:01:12 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2022-03-29 21:29:08 +08:00
|
|
|
* work type definitions
|
2019-03-17 16:01:12 +08:00
|
|
|
*/
|
|
|
|
enum
|
|
|
|
{
|
2019-04-22 11:41:17 +08:00
|
|
|
RT_WORK_TYPE_DELAYED = 0x0001,
|
2019-03-17 16:01:12 +08:00
|
|
|
};
|
|
|
|
|
2017-10-15 22:56:46 +08:00
|
|
|
/* workqueue implementation */
|
|
|
|
struct rt_workqueue
|
|
|
|
{
|
|
|
|
rt_list_t work_list;
|
2021-02-06 20:08:31 +08:00
|
|
|
rt_list_t delayed_list;
|
2017-10-15 22:56:46 +08:00
|
|
|
struct rt_work *work_current; /* current work */
|
2017-10-17 17:53:01 +08:00
|
|
|
|
2019-03-17 16:01:12 +08:00
|
|
|
struct rt_semaphore sem;
|
2017-10-15 22:56:46 +08:00
|
|
|
rt_thread_t work_thread;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct rt_work
|
|
|
|
{
|
|
|
|
rt_list_t list;
|
|
|
|
|
2019-03-17 16:01:12 +08:00
|
|
|
void (*work_func)(struct rt_work *work, void *work_data);
|
2017-10-15 22:56:46 +08:00
|
|
|
void *work_data;
|
2019-03-17 16:01:12 +08:00
|
|
|
rt_uint16_t flags;
|
|
|
|
rt_uint16_t type;
|
2019-08-05 14:18:15 +08:00
|
|
|
struct rt_timer timer;
|
|
|
|
struct rt_workqueue *workqueue;
|
2019-03-17 16:01:12 +08:00
|
|
|
};
|
|
|
|
|
2017-10-15 22:56:46 +08:00
|
|
|
#ifdef RT_USING_HEAP
|
|
|
|
/**
|
|
|
|
* WorkQueue for DeviceDriver
|
|
|
|
*/
|
2022-01-17 04:15:08 +08:00
|
|
|
void rt_work_init(struct rt_work *work, void (*work_func)(struct rt_work *work, void *work_data), void *work_data);
|
2019-03-17 16:01:12 +08:00
|
|
|
struct rt_workqueue *rt_workqueue_create(const char *name, rt_uint16_t stack_size, rt_uint8_t priority);
|
|
|
|
rt_err_t rt_workqueue_destroy(struct rt_workqueue *queue);
|
|
|
|
rt_err_t rt_workqueue_dowork(struct rt_workqueue *queue, struct rt_work *work);
|
2022-01-17 04:15:08 +08:00
|
|
|
rt_err_t rt_workqueue_submit_work(struct rt_workqueue *queue, struct rt_work *work, rt_tick_t ticks);
|
2019-03-17 16:01:12 +08:00
|
|
|
rt_err_t rt_workqueue_cancel_work(struct rt_workqueue *queue, struct rt_work *work);
|
|
|
|
rt_err_t rt_workqueue_cancel_work_sync(struct rt_workqueue *queue, struct rt_work *work);
|
2021-02-07 11:14:59 +08:00
|
|
|
rt_err_t rt_workqueue_cancel_all_work(struct rt_workqueue *queue);
|
2021-10-21 03:48:07 +08:00
|
|
|
rt_err_t rt_workqueue_urgent_work(struct rt_workqueue *queue, struct rt_work *work);
|
2019-03-17 16:01:12 +08:00
|
|
|
|
|
|
|
#ifdef RT_USING_SYSTEM_WORKQUEUE
|
2022-01-17 04:15:08 +08:00
|
|
|
rt_err_t rt_work_submit(struct rt_work *work, rt_tick_t ticks);
|
2022-01-17 05:00:55 +08:00
|
|
|
rt_err_t rt_work_urgent(struct rt_work *work);
|
2019-03-17 16:01:12 +08:00
|
|
|
rt_err_t rt_work_cancel(struct rt_work *work);
|
2021-07-22 17:00:21 +08:00
|
|
|
#endif /* RT_USING_SYSTEM_WORKQUEUE */
|
2019-03-17 16:01:12 +08:00
|
|
|
|
2022-04-02 16:21:45 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2019-03-17 16:01:12 +08:00
|
|
|
|
2021-07-22 17:00:21 +08:00
|
|
|
#endif /* RT_USING_HEAP */
|
2017-10-15 22:56:46 +08:00
|
|
|
|
|
|
|
#endif
|