[workqueue] time参数改为ticks,防止误解单位为ms
This commit is contained in:
parent
3a789b3317
commit
36cbc1fd2f
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
@ -54,37 +54,22 @@ struct rt_work
|
||||||
/**
|
/**
|
||||||
* WorkQueue for DeviceDriver
|
* WorkQueue for DeviceDriver
|
||||||
*/
|
*/
|
||||||
|
void rt_work_init(struct rt_work *work, void (*work_func)(struct rt_work *work, void *work_data), void *work_data);
|
||||||
struct rt_workqueue *rt_workqueue_create(const char *name, rt_uint16_t stack_size, rt_uint8_t priority);
|
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_destroy(struct rt_workqueue *queue);
|
||||||
rt_err_t rt_workqueue_dowork(struct rt_workqueue *queue, struct rt_work *work);
|
rt_err_t rt_workqueue_dowork(struct rt_workqueue *queue, struct rt_work *work);
|
||||||
rt_err_t rt_workqueue_submit_work(struct rt_workqueue *queue, struct rt_work *work, rt_tick_t time);
|
rt_err_t rt_workqueue_submit_work(struct rt_workqueue *queue, struct rt_work *work, rt_tick_t ticks);
|
||||||
rt_err_t rt_workqueue_cancel_work(struct rt_workqueue *queue, struct rt_work *work);
|
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);
|
rt_err_t rt_workqueue_cancel_work_sync(struct rt_workqueue *queue, struct rt_work *work);
|
||||||
rt_err_t rt_workqueue_cancel_all_work(struct rt_workqueue *queue);
|
rt_err_t rt_workqueue_cancel_all_work(struct rt_workqueue *queue);
|
||||||
rt_err_t rt_workqueue_urgent_work(struct rt_workqueue *queue, struct rt_work *work);
|
rt_err_t rt_workqueue_urgent_work(struct rt_workqueue *queue, struct rt_work *work);
|
||||||
|
|
||||||
#ifdef RT_USING_SYSTEM_WORKQUEUE
|
#ifdef RT_USING_SYSTEM_WORKQUEUE
|
||||||
rt_err_t rt_work_submit(struct rt_work *work, rt_tick_t time);
|
rt_err_t rt_work_submit(struct rt_work *work, rt_tick_t ticks);
|
||||||
rt_err_t rt_work_cancel(struct rt_work *work);
|
rt_err_t rt_work_cancel(struct rt_work *work);
|
||||||
#endif /* RT_USING_SYSTEM_WORKQUEUE */
|
#endif /* RT_USING_SYSTEM_WORKQUEUE */
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Initialize a work item, binding with a callback function.
|
|
||||||
*
|
|
||||||
* @param work A pointer to the work item object.
|
|
||||||
* @param work_func A callback function that will be called when this work item is executed.
|
|
||||||
* @param work_data A user data passed to the callback function as the second parameter.
|
|
||||||
*/
|
|
||||||
rt_inline void rt_work_init(struct rt_work *work, void (*work_func)(struct rt_work *work, void *work_data),
|
|
||||||
void *work_data)
|
|
||||||
{
|
|
||||||
rt_list_init(&(work->list));
|
|
||||||
work->work_func = work_func;
|
|
||||||
work->work_data = work_data;
|
|
||||||
work->workqueue = RT_NULL;
|
|
||||||
work->flags = 0;
|
|
||||||
work->type = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* RT_USING_HEAP */
|
#endif /* RT_USING_HEAP */
|
||||||
|
|
||||||
|
|
|
@ -210,6 +210,30 @@ static void _delayed_work_timeout_handler(void *parameter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initialize a work item, binding with a callback function.
|
||||||
|
*
|
||||||
|
* @param work is a pointer to the work item object.
|
||||||
|
*
|
||||||
|
* @param work_func is a callback function that will be called when this work item is executed.
|
||||||
|
*
|
||||||
|
* @param work_data is a user data passed to the callback function as the second parameter.
|
||||||
|
*/
|
||||||
|
void rt_work_init(struct rt_work *work,
|
||||||
|
void (*work_func)(struct rt_work *work, void *work_data),
|
||||||
|
void *work_data)
|
||||||
|
{
|
||||||
|
RT_ASSERT(work != RT_NULL);
|
||||||
|
RT_ASSERT(work_func != RT_NULL);
|
||||||
|
|
||||||
|
rt_list_init(&(work->list));
|
||||||
|
work->work_func = work_func;
|
||||||
|
work->work_data = work_data;
|
||||||
|
work->workqueue = RT_NULL;
|
||||||
|
work->flags = 0;
|
||||||
|
work->type = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create a work queue with a thread inside.
|
* @brief Create a work queue with a thread inside.
|
||||||
*
|
*
|
||||||
|
@ -292,20 +316,21 @@ rt_err_t rt_workqueue_dowork(struct rt_workqueue *queue, struct rt_work *work)
|
||||||
*
|
*
|
||||||
* @param work is a pointer to the work item object.
|
* @param work is a pointer to the work item object.
|
||||||
*
|
*
|
||||||
* @param time is the delay time (unit: OS ticks) for the work item to be submitted to the work queue.
|
* @param ticks is the delay ticks for the work item to be submitted to the work queue.
|
||||||
*
|
*
|
||||||
* NOTE: The max timeout tick should be no more than (RT_TICK_MAX/2 - 1)
|
* NOTE: The max timeout tick should be no more than (RT_TICK_MAX/2 - 1)
|
||||||
*
|
*
|
||||||
* @return RT_EOK Success.
|
* @return RT_EOK Success.
|
||||||
* -RT_EBUSY This work item is executing.
|
* -RT_EBUSY This work item is executing.
|
||||||
* -RT_ERROR The time parameter is invalid.
|
* -RT_ERROR The ticks parameter is invalid.
|
||||||
*/
|
*/
|
||||||
rt_err_t rt_workqueue_submit_work(struct rt_workqueue *queue, struct rt_work *work, rt_tick_t time)
|
rt_err_t rt_workqueue_submit_work(struct rt_workqueue *queue, struct rt_work *work, rt_tick_t ticks)
|
||||||
{
|
{
|
||||||
RT_ASSERT(queue != RT_NULL);
|
RT_ASSERT(queue != RT_NULL);
|
||||||
RT_ASSERT(work != RT_NULL);
|
RT_ASSERT(work != RT_NULL);
|
||||||
|
RT_ASSERT(ticks < RT_TICK_MAX / 2);
|
||||||
|
|
||||||
return _workqueue_submit_work(queue, work, time);
|
return _workqueue_submit_work(queue, work, ticks);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -422,24 +447,25 @@ rt_err_t rt_workqueue_cancel_all_work(struct rt_workqueue *queue)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef RT_USING_SYSTEM_WORKQUEUE
|
#ifdef RT_USING_SYSTEM_WORKQUEUE
|
||||||
static struct rt_workqueue *sys_workq;
|
|
||||||
|
static struct rt_workqueue *sys_workq; /* system work queue */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Submit a work item to the system work queue with a delay.
|
* @brief Submit a work item to the system work queue with a delay.
|
||||||
*
|
*
|
||||||
* @param work is a pointer to the work item object.
|
* @param work is a pointer to the work item object.
|
||||||
*
|
*
|
||||||
* @param time is the delay time (unit: OS ticks) for the work item to be submitted to the work queue.
|
* @param ticks is the delay OS ticks for the work item to be submitted to the work queue.
|
||||||
*
|
*
|
||||||
* NOTE: The max timeout tick should be no more than (RT_TICK_MAX/2 - 1)
|
* NOTE: The max timeout tick should be no more than (RT_TICK_MAX/2 - 1)
|
||||||
*
|
*
|
||||||
* @return RT_EOK Success.
|
* @return RT_EOK Success.
|
||||||
* -RT_EBUSY This work item is executing.
|
* -RT_EBUSY This work item is executing.
|
||||||
* -RT_ERROR The time parameter is invalid.
|
* -RT_ERROR The ticks parameter is invalid.
|
||||||
*/
|
*/
|
||||||
rt_err_t rt_work_submit(struct rt_work *work, rt_tick_t time)
|
rt_err_t rt_work_submit(struct rt_work *work, rt_tick_t ticks)
|
||||||
{
|
{
|
||||||
return rt_workqueue_submit_work(sys_workq, work, time);
|
return rt_workqueue_submit_work(sys_workq, work, ticks);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -263,7 +263,7 @@ void rt_timer_init(rt_timer_t timer,
|
||||||
/* parameter check */
|
/* parameter check */
|
||||||
RT_ASSERT(timer != RT_NULL);
|
RT_ASSERT(timer != RT_NULL);
|
||||||
RT_ASSERT(timeout != RT_NULL);
|
RT_ASSERT(timeout != RT_NULL);
|
||||||
RT_ASSERT(timer->init_tick < RT_TICK_MAX / 2);
|
RT_ASSERT(time < RT_TICK_MAX / 2);
|
||||||
|
|
||||||
/* timer object initialization */
|
/* timer object initialization */
|
||||||
rt_object_init(&(timer->parent), RT_Object_Class_Timer, name);
|
rt_object_init(&(timer->parent), RT_Object_Class_Timer, name);
|
||||||
|
@ -332,7 +332,7 @@ rt_timer_t rt_timer_create(const char *name,
|
||||||
|
|
||||||
/* parameter check */
|
/* parameter check */
|
||||||
RT_ASSERT(timeout != RT_NULL);
|
RT_ASSERT(timeout != RT_NULL);
|
||||||
RT_ASSERT(timer->init_tick < RT_TICK_MAX / 2);
|
RT_ASSERT(time < RT_TICK_MAX / 2);
|
||||||
|
|
||||||
/* allocate a object */
|
/* allocate a object */
|
||||||
timer = (struct rt_timer *)rt_object_allocate(RT_Object_Class_Timer, name);
|
timer = (struct rt_timer *)rt_object_allocate(RT_Object_Class_Timer, name);
|
||||||
|
|
Loading…
Reference in New Issue