mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-02-06 00:45:22 +08:00
Some checks are pending
AutoTestCI / ${{ matrix.legs.UTEST }} (map[CONFIG_FILE:cpp11/cpp11.conf QEMU_ARCH:arm QEMU_MACHINE:vexpress-a9 RTT_BSP:bsp/qemu-vexpress-a9 RUN:yes SD_FILE:sd.bin UTEST:components/cpp11]) (push) Waiting to run
AutoTestCI / ${{ matrix.legs.UTEST }} (map[CONFIG_FILE:kernel/atomic.conf QEMU_ARCH:arm QEMU_MACHINE:vexpress-a9 RTT_BSP:bsp/qemu-vexpress-a9 RUN:yes SD_FILE:sd.bin UTEST:kernel/atomic]) (push) Waiting to run
AutoTestCI / ${{ matrix.legs.UTEST }} (map[CONFIG_FILE:kernel/atomic.conf QEMU_ARCH:riscv64 QEMU_MACHINE:virt RTT_BSP:bsp/qemu-virt64-riscv RUN:yes SD_FILE:None UTEST:kernel/atomic/riscv64]) (push) Waiting to run
AutoTestCI / ${{ matrix.legs.UTEST }} (map[CONFIG_FILE:kernel/atomic_c11.conf QEMU_ARCH:arm QEMU_MACHINE:vexpress-a9 RTT_BSP:bsp/qemu-vexpress-a9 RUN:yes SD_FILE:sd.bin UTEST:kernel/atomic_c11]) (push) Waiting to run
AutoTestCI / ${{ matrix.legs.UTEST }} (map[CONFIG_FILE:kernel/atomic_c11.conf QEMU_ARCH:riscv64 QEMU_MACHINE:virt RTT_BSP:bsp/qemu-virt64-riscv RUN:yes SD_FILE:None UTEST:kernel/atomic_c11/riscv64]) (push) Waiting to run
AutoTestCI / ${{ matrix.legs.UTEST }} (map[CONFIG_FILE:kernel/device.conf QEMU_ARCH:arm QEMU_MACHINE:vexpress-a9 RTT_BSP:bsp/qemu-vexpress-a9 RUN:yes SD_FILE:sd.bin UTEST:kernel/device]) (push) Waiting to run
AutoTestCI / ${{ matrix.legs.UTEST }} (map[CONFIG_FILE:kernel/ipc.conf QEMU_ARCH:arm QEMU_MACHINE:vexpress-a9 RTT_BSP:bsp/qemu-vexpress-a9 RUN:yes SD_FILE:sd.bin UTEST:kernel/ipc]) (push) Waiting to run
AutoTestCI / ${{ matrix.legs.UTEST }} (map[CONFIG_FILE:kernel/irq.conf QEMU_ARCH:arm QEMU_MACHINE:vexpress-a9 RTT_BSP:bsp/qemu-vexpress-a9 RUN:yes SD_FILE:sd.bin UTEST:kernel/irq]) (push) Waiting to run
AutoTestCI / ${{ matrix.legs.UTEST }} (map[CONFIG_FILE:kernel/mem.conf QEMU_ARCH:arm QEMU_MACHINE:vexpress-a9 RTT_BSP:bsp/qemu-vexpress-a9 RUN:yes SD_FILE:sd.bin UTEST:kernel/mem]) (push) Waiting to run
AutoTestCI / ${{ matrix.legs.UTEST }} (map[CONFIG_FILE:kernel/mem.conf QEMU_ARCH:riscv64 QEMU_MACHINE:virt RTT_BSP:bsp/qemu-virt64-riscv RUN:yes SD_FILE:None UTEST:kernel/mem/riscv64]) (push) Waiting to run
AutoTestCI / ${{ matrix.legs.UTEST }} (map[CONFIG_FILE:kernel/thread.conf QEMU_ARCH:arm QEMU_MACHINE:vexpress-a9 RTT_BSP:bsp/qemu-vexpress-a9 RUN:yes SD_FILE:sd.bin UTEST:kernel/thread]) (push) Waiting to run
AutoTestCI / ${{ matrix.legs.UTEST }} (map[CONFIG_FILE:kernel/timer.conf QEMU_ARCH:arm QEMU_MACHINE:vexpress-a9 RTT_BSP:bsp/qemu-vexpress-a9 RUN:yes SD_FILE:sd.bin UTEST:kernel/timer]) (push) Waiting to run
AutoTestCI / ${{ matrix.legs.UTEST }} (map[CONFIG_FILE:rtsmart/base.conf QEMU_ARCH:aarch64 QEMU_MACHINE:virt RTT_BSP:bsp/qemu-virt64-aarch64 RUN:no SD_FILE:sd.bin UTEST:rtsmart/aarch64]) (push) Waiting to run
AutoTestCI / ${{ matrix.legs.UTEST }} (map[CONFIG_FILE:rtsmart/base.conf QEMU_ARCH:arm QEMU_MACHINE:vexpress-a9 RTT_BSP:bsp/qemu-vexpress-a9 RUN:no SD_FILE:sd.bin UTEST:rtsmart/arm]) (push) Waiting to run
AutoTestCI / ${{ matrix.legs.UTEST }} (map[CONFIG_FILE:rtsmart/base.conf QEMU_ARCH:riscv64 QEMU_MACHINE:virt RTT_BSP:bsp/qemu-virt64-riscv RUN:yes SD_FILE:None UTEST:rtsmart/riscv64]) (push) Waiting to run
AutoTestCI / ${{ matrix.legs.UTEST }} (map[CONFIG_FILE:utest_self/self.conf QEMU_ARCH:arm QEMU_MACHINE:vexpress-a9 RTT_BSP:bsp/qemu-vexpress-a9 RUN:yes SD_FILE:sd.bin UTEST:components/utest]) (push) Waiting to run
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (map[RTT_BSP:ESP32C3 RTT_TOOL_CHAIN:sourcery-riscv32-esp32 SUB_RTT_BSP:[ESP32_C3]]) (push) Waiting to run
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (map[RTT_BSP:Infineon_TI_microchip RTT_TOOL_CHAIN:sourcery-arm SUB_RTT_BSP:[Infineon/psoc6-cy8ckit-062S2-43012 Infineon/psoc6-cy8ckit-062-BLE Infineon/psoc6-cy8ckit-062s4 Infineon/psoc6-cy8ckit-062-WIFI-BT Infineon/psoc6-cy8c… (push) Waiting to run
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (map[RTT_BSP:RT-Thread Online Packages (STM32F407 RT-Spark) RTT_TOOL_CHAIN:sourcery-arm SUB_RTT_BSP:[stm32/stm32f407-rt-spark]]) (push) Waiting to run
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (map[RTT_BSP:RTduino/Arduino Libraries (Raspberry Pico) RTT_TOOL_CHAIN:sourcery-arm SUB_RTT_BSP:[raspberry-pico]]) (push) Waiting to run
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (map[RTT_BSP:RTduino/Arduino Libraries (STM32F412 Nucleo) RTT_TOOL_CHAIN:sourcery-arm SUB_RTT_BSP:[stm32/stm32f412-st-nucleo]]) (push) Waiting to run
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (map[RTT_BSP:aarch64 RTT_TOOL_CHAIN:sourcery-aarch64 SUB_RTT_BSP:[qemu-virt64-aarch64 raspberry-pi/raspi3-64 raspberry-pi/raspi4-64 phytium/aarch64]]) (push) Waiting to run
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (map[RTT_BSP:gd32_n32_apm32 RTT_TOOL_CHAIN:sourcery-arm SUB_RTT_BSP:[gd32/arm/gd32103c-eval gd32/arm/gd32105c-eval gd32/arm/gd32105r-start gd32/arm/gd32107c-eval gd32/arm/gd32205r-start gd32/arm/gd32207i-eval gd32/arm/gd32303… (push) Waiting to run
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (map[RTT_BSP:hpmicro RTT_TOOL_CHAIN:RISC-V-GCC-RV32 SUB_RTT_BSP:[hpmicro/hpm6750evkmini hpmicro/hpm6750evk hpmicro/hpm6750evk2 hpmicro/hpm6300evk hpmicro/hpm6200evk hpmicro/hpm5300evk hpmicro/hpm5301evklite hpmicro/hpm6800evk… (push) Waiting to run
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (map[RTT_BSP:i386-unknown RTT_TOOL_CHAIN:sourcery-i386-unknown-elf SUB_RTT_BSP:[x86]]) (push) Waiting to run
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (map[RTT_BSP:llvm-arm RTT_TOOL_CHAIN:llvm-arm SUB_RTT_BSP:[stm32/stm32l475-atk-pandora]]) (push) Waiting to run
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (map[RTT_BSP:mips RTT_TOOL_CHAIN:sourcery-mips SUB_RTT_BSP:[loongson/ls1bdev loongson/ls2kdev loongson/ls1cdev]]) (push) Waiting to run
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (map[RTT_BSP:nordic(yml) RTT_TOOL_CHAIN:sourcery-arm SUB_RTT_BSP:[nrf5x/nrf51822 nrf5x/nrf52832 nrf5x/nrf52833 nrf5x/nrf52840 nrf5x/nrf5340]]) (push) Waiting to run
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (map[RTT_BSP:nuvoton RTT_TOOL_CHAIN:sourcery-arm SUB_RTT_BSP:[nuvoton/numaker-pfm-m487 nuvoton/numaker-hmi-ma35d1 nuvoton/numaker-iot-m487 nuvoton/numaker-m032ki nuvoton/numaker-iot-m467 nuvoton/numaker-m467hj nuvoton/nk-n9h3… (push) Waiting to run
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (map[RTT_BSP:nxp_renesas RTT_TOOL_CHAIN:sourcery-arm SUB_RTT_BSP:[nxp/lpc/lpc55sxx/lpc55s69_nxp_evk nxp/lpc/lpc55sxx/lpc55s28_nxp_evk nxp/lpc/lpc55sxx/lpc55s06_nxp_evk nxp/lpc/lpc55sxx/lpc55s16_nxp_evk nxp/lpc/lpc55sxx/lpc55s… (push) Waiting to run
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (map[RTT_BSP:others_at32_hc32_ht32 RTT_TOOL_CHAIN:sourcery-arm SUB_RTT_BSP:[qemu-vexpress-a9 airm2m/air32f103 acm32/acm32f0x0-nucleo CME_M7 apollo2 asm9260t allwinner_tina ft32/ft32f072xb-starter mini2440 at91/at91sam9g45 at9… (push) Waiting to run
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (map[RTT_BSP:riscv-none RTT_TOOL_CHAIN:sourcery-riscv-none-embed SUB_RTT_BSP:[k210]]) (push) Waiting to run
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (map[RTT_BSP:riscv64-unknown RTT_TOOL_CHAIN:sourcery-riscv64-unknown-elf SUB_RTT_BSP:[bluetrum/ab32vg1-ab-prougen bouffalo_lab/bl60x bouffalo_lab/bl70x]]) (push) Waiting to run
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (map[RTT_BSP:simulator RTT_TOOL_CHAIN:gcc SUB_RTT_BSP:[simulator]]) (push) Waiting to run
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (map[RTT_BSP:stm32_f2_f4 RTT_TOOL_CHAIN:sourcery-arm SUB_RTT_BSP:[stm32/stm32f207-st-nucleo stm32/stm32f302-st-nucleo stm32/stm32f334-st-nucleo stm32/stm32f401-st-nucleo stm32/stm32f401-weact-blackpill stm32/stm32f405-smdz-br… (push) Waiting to run
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (map[RTT_BSP:stm32_f7_g0_h7_mp15_u5_h5_wb5 RTT_TOOL_CHAIN:sourcery-arm SUB_RTT_BSP:[stm32/stm32f746-st-disco stm32/stm32f746-st-nucleo stm32/stm32f767-atk-apollo stm32/stm32f767-fire-challenger-v1 stm32/stm32f767-st-nucleo st… (push) Waiting to run
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (map[RTT_BSP:stm32l4_f0_f1 RTT_TOOL_CHAIN:sourcery-arm SUB_RTT_BSP:[stm32/stm32l4r5-st-nucleo stm32/stm32l4r9-st-eval stm32/stm32l4r9-st-sensortile-box stm32/stm32l010-st-nucleo stm32/stm32l053-st-nucleo stm32/stm32l412-st-nu… (push) Waiting to run
BSP compilation with more drivers / BSP Compilation with More Drivers (push) Waiting to run
pkgs_test / change (push) Waiting to run
468 lines
13 KiB
C
468 lines
13 KiB
C
/*
|
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*
|
|
* Change Logs:
|
|
* Date Author Notes
|
|
* 2017-02-27 Bernard fix the re-work issue.
|
|
* 2021-08-01 Meco Man remove rt_delayed_work_init()
|
|
* 2021-08-14 Jackistang add comments for function interface
|
|
* 2022-01-16 Meco Man add rt_work_urgent()
|
|
* 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
|
|
* 2024-12-21 yuqingli delete timer, using list
|
|
*/
|
|
|
|
#include <rthw.h>
|
|
#include <rtdevice.h>
|
|
|
|
#ifdef RT_USING_HEAP
|
|
|
|
rt_inline rt_err_t _workqueue_work_completion(struct rt_workqueue *queue)
|
|
{
|
|
rt_err_t result;
|
|
|
|
while (1)
|
|
{
|
|
/* try to take condition semaphore */
|
|
result = rt_sem_trytake(&(queue->sem));
|
|
if (result == -RT_ETIMEOUT)
|
|
{
|
|
/* it's timeout, release this semaphore */
|
|
rt_sem_release(&(queue->sem));
|
|
}
|
|
else if (result == RT_EOK)
|
|
{
|
|
/* keep the sem value = 0 */
|
|
result = RT_EOK;
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
result = -RT_ERROR;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
static void _workqueue_thread_entry(void *parameter)
|
|
{
|
|
rt_base_t level;
|
|
struct rt_work *work;
|
|
struct rt_workqueue *queue;
|
|
rt_tick_t current_tick;
|
|
rt_int32_t delay_tick;
|
|
void (*work_func)(struct rt_work *work, void *work_data);
|
|
void *work_data;
|
|
|
|
queue = (struct rt_workqueue *)parameter;
|
|
RT_ASSERT(queue != RT_NULL);
|
|
|
|
while (1)
|
|
{
|
|
level = rt_spin_lock_irqsave(&(queue->spinlock));
|
|
|
|
/* timer check */
|
|
current_tick = rt_tick_get();
|
|
delay_tick = RT_WAITING_FOREVER;
|
|
while (!rt_list_isempty(&(queue->delayed_list)))
|
|
{
|
|
work = rt_list_entry(queue->delayed_list.next, struct rt_work, list);
|
|
if ((current_tick - work->timeout_tick) < RT_TICK_MAX / 2)
|
|
{
|
|
rt_list_remove(&(work->list));
|
|
rt_list_insert_after(queue->work_list.prev, &(work->list));
|
|
work->flags &= ~RT_WORK_STATE_SUBMITTING;
|
|
work->flags |= RT_WORK_STATE_PENDING;
|
|
}
|
|
else
|
|
{
|
|
delay_tick = work->timeout_tick - current_tick;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (rt_list_isempty(&(queue->work_list)))
|
|
{
|
|
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
|
|
/* wait for work completion */
|
|
rt_completion_wait(&(queue->wakeup_completion), delay_tick);
|
|
continue;
|
|
}
|
|
|
|
/* we have work to do with. */
|
|
work = rt_list_entry(queue->work_list.next, struct rt_work, list);
|
|
rt_list_remove(&(work->list));
|
|
queue->work_current = work;
|
|
work->flags &= ~RT_WORK_STATE_PENDING;
|
|
work->workqueue = RT_NULL;
|
|
work_func = work->work_func;
|
|
work_data = work->work_data;
|
|
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
|
|
|
|
/* do work */
|
|
work_func(work, work_data);
|
|
/* clean current work */
|
|
queue->work_current = RT_NULL;
|
|
|
|
/* ack work completion */
|
|
_workqueue_work_completion(queue);
|
|
}
|
|
}
|
|
|
|
static rt_err_t _workqueue_submit_work(struct rt_workqueue *queue,
|
|
struct rt_work *work, rt_tick_t ticks)
|
|
{
|
|
rt_base_t level;
|
|
rt_err_t err = RT_EOK;
|
|
struct rt_work *work_tmp;
|
|
rt_list_t *list_tmp;
|
|
|
|
level = rt_spin_lock_irqsave(&(queue->spinlock));
|
|
/* remove list */
|
|
rt_list_remove(&(work->list));
|
|
work->flags = 0;
|
|
|
|
if (ticks == 0)
|
|
{
|
|
rt_list_insert_after(queue->work_list.prev, &(work->list));
|
|
work->flags |= RT_WORK_STATE_PENDING;
|
|
work->workqueue = queue;
|
|
|
|
rt_completion_done(&(queue->wakeup_completion));
|
|
err = RT_EOK;
|
|
}
|
|
else if (ticks < RT_TICK_MAX / 2)
|
|
{
|
|
/* insert delay work list */
|
|
work->flags |= RT_WORK_STATE_SUBMITTING;
|
|
work->workqueue = queue;
|
|
work->timeout_tick = rt_tick_get() + ticks;
|
|
|
|
list_tmp = &(queue->delayed_list);
|
|
rt_list_for_each_entry(work_tmp, &(queue->delayed_list), list)
|
|
{
|
|
if ((work_tmp->timeout_tick - work->timeout_tick) < RT_TICK_MAX / 2)
|
|
{
|
|
list_tmp = &(work_tmp->list);
|
|
break;
|
|
}
|
|
}
|
|
rt_list_insert_before(list_tmp, &(work->list));
|
|
|
|
rt_completion_done(&(queue->wakeup_completion));
|
|
err = RT_EOK;
|
|
}
|
|
else
|
|
{
|
|
err = -RT_ERROR;
|
|
}
|
|
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
|
|
return err;
|
|
}
|
|
|
|
static rt_err_t _workqueue_cancel_work(struct rt_workqueue *queue, struct rt_work *work)
|
|
{
|
|
rt_base_t level;
|
|
rt_err_t err;
|
|
|
|
level = rt_spin_lock_irqsave(&(queue->spinlock));
|
|
rt_list_remove(&(work->list));
|
|
work->flags = 0;
|
|
err = queue->work_current != work ? RT_EOK : -RT_EBUSY;
|
|
work->workqueue = RT_NULL;
|
|
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
|
|
return err;
|
|
}
|
|
|
|
/**
|
|
* @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.
|
|
*
|
|
* @param name is a name of the work queue thread.
|
|
*
|
|
* @param stack_size is stack size of the work queue thread.
|
|
*
|
|
* @param priority is a priority of the work queue thread.
|
|
*
|
|
* @return Return a pointer to the workqueue object. It will return RT_NULL if failed.
|
|
*/
|
|
struct rt_workqueue *rt_workqueue_create(const char *name, rt_uint16_t stack_size, rt_uint8_t priority)
|
|
{
|
|
struct rt_workqueue *queue = RT_NULL;
|
|
|
|
queue = (struct rt_workqueue *)RT_KERNEL_MALLOC(sizeof(struct rt_workqueue));
|
|
if (queue != RT_NULL)
|
|
{
|
|
/* initialize work list */
|
|
rt_list_init(&(queue->work_list));
|
|
rt_list_init(&(queue->delayed_list));
|
|
queue->work_current = RT_NULL;
|
|
rt_sem_init(&(queue->sem), "wqueue", 0, RT_IPC_FLAG_FIFO);
|
|
rt_completion_init(&(queue->wakeup_completion));
|
|
|
|
/* create the work thread */
|
|
queue->work_thread = rt_thread_create(name, _workqueue_thread_entry, queue, stack_size, priority, 10);
|
|
if (queue->work_thread == RT_NULL)
|
|
{
|
|
rt_sem_detach(&(queue->sem));
|
|
RT_KERNEL_FREE(queue);
|
|
return RT_NULL;
|
|
}
|
|
|
|
rt_spin_lock_init(&(queue->spinlock));
|
|
rt_thread_startup(queue->work_thread);
|
|
}
|
|
|
|
return queue;
|
|
}
|
|
|
|
/**
|
|
* @brief Destroy a work queue.
|
|
*
|
|
* @param queue is a pointer to the workqueue object.
|
|
*
|
|
* @return RT_EOK Success.
|
|
*/
|
|
rt_err_t rt_workqueue_destroy(struct rt_workqueue *queue)
|
|
{
|
|
RT_ASSERT(queue != RT_NULL);
|
|
|
|
rt_workqueue_cancel_all_work(queue);
|
|
rt_thread_delete(queue->work_thread);
|
|
rt_sem_detach(&(queue->sem));
|
|
RT_KERNEL_FREE(queue);
|
|
|
|
return RT_EOK;
|
|
}
|
|
|
|
/**
|
|
* @brief Submit a work item to the work queue without delay.
|
|
*
|
|
* @param queue is a pointer to the workqueue object.
|
|
*
|
|
* @param work is a pointer to the work item object.
|
|
*
|
|
* @return RT_EOK Success.
|
|
*/
|
|
rt_err_t rt_workqueue_dowork(struct rt_workqueue *queue, struct rt_work *work)
|
|
{
|
|
RT_ASSERT(queue != RT_NULL);
|
|
RT_ASSERT(work != RT_NULL);
|
|
|
|
return _workqueue_submit_work(queue, work, 0);
|
|
}
|
|
|
|
/**
|
|
* @brief Submit a work item to the work queue with a delay.
|
|
*
|
|
* @param queue is a pointer to the workqueue object.
|
|
*
|
|
* @param work is a pointer to the work item object.
|
|
*
|
|
* @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)
|
|
*
|
|
* @return RT_EOK Success.
|
|
* -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 ticks)
|
|
{
|
|
RT_ASSERT(queue != RT_NULL);
|
|
RT_ASSERT(work != RT_NULL);
|
|
RT_ASSERT(ticks < RT_TICK_MAX / 2);
|
|
|
|
return _workqueue_submit_work(queue, work, ticks);
|
|
}
|
|
|
|
/**
|
|
* @brief Submit a work item to the work queue without delay. This work item will be executed after the current work item.
|
|
*
|
|
* @param queue is a pointer to the workqueue object.
|
|
*
|
|
* @param work is a pointer to the work item object.
|
|
*
|
|
* @return RT_EOK Success.
|
|
*/
|
|
rt_err_t rt_workqueue_urgent_work(struct rt_workqueue *queue, struct rt_work *work)
|
|
{
|
|
rt_base_t level;
|
|
|
|
RT_ASSERT(queue != RT_NULL);
|
|
RT_ASSERT(work != RT_NULL);
|
|
|
|
level = rt_spin_lock_irqsave(&(queue->spinlock));
|
|
/* NOTE: the work MUST be initialized firstly */
|
|
rt_list_remove(&(work->list));
|
|
rt_list_insert_after(&queue->work_list, &(work->list));
|
|
|
|
rt_completion_done(&(queue->wakeup_completion));
|
|
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
|
|
|
|
return RT_EOK;
|
|
}
|
|
|
|
/**
|
|
* @brief Cancel a work item in the work queue.
|
|
*
|
|
* @param queue is a pointer to the workqueue object.
|
|
*
|
|
* @param work is a pointer to the work item object.
|
|
*
|
|
* @return RT_EOK Success.
|
|
* -RT_EBUSY This work item is executing.
|
|
*/
|
|
rt_err_t rt_workqueue_cancel_work(struct rt_workqueue *queue, struct rt_work *work)
|
|
{
|
|
RT_ASSERT(work != RT_NULL);
|
|
RT_ASSERT(queue != RT_NULL);
|
|
|
|
return _workqueue_cancel_work(queue, work);
|
|
}
|
|
|
|
/**
|
|
* @brief Cancel a work item in the work queue. If the work item is executing, this function will block until it is done.
|
|
*
|
|
* @param queue is a pointer to the workqueue object.
|
|
*
|
|
* @param work is a pointer to the work item object.
|
|
*
|
|
* @return RT_EOK Success.
|
|
*/
|
|
rt_err_t rt_workqueue_cancel_work_sync(struct rt_workqueue *queue, struct rt_work *work)
|
|
{
|
|
RT_ASSERT(queue != RT_NULL);
|
|
RT_ASSERT(work != RT_NULL);
|
|
|
|
if (queue->work_current == work) /* it's current work in the queue */
|
|
{
|
|
/* wait for work completion */
|
|
rt_sem_take(&(queue->sem), RT_WAITING_FOREVER);
|
|
/* Note that because work items are automatically deleted after execution, they do not need to be deleted again */
|
|
}
|
|
else
|
|
{
|
|
_workqueue_cancel_work(queue, work);
|
|
}
|
|
|
|
return RT_EOK;
|
|
}
|
|
|
|
/**
|
|
* @brief This function will cancel all work items in work queue.
|
|
*
|
|
* @param queue is a pointer to the workqueue object.
|
|
*
|
|
* @return RT_EOK Success.
|
|
*/
|
|
rt_err_t rt_workqueue_cancel_all_work(struct rt_workqueue *queue)
|
|
{
|
|
struct rt_work *work;
|
|
|
|
RT_ASSERT(queue != RT_NULL);
|
|
|
|
/* cancel work */
|
|
rt_enter_critical();
|
|
while (rt_list_isempty(&queue->work_list) == RT_FALSE)
|
|
{
|
|
work = rt_list_first_entry(&queue->work_list, struct rt_work, list);
|
|
_workqueue_cancel_work(queue, work);
|
|
}
|
|
/* cancel delay work */
|
|
while (rt_list_isempty(&queue->delayed_list) == RT_FALSE)
|
|
{
|
|
work = rt_list_first_entry(&queue->delayed_list, struct rt_work, list);
|
|
_workqueue_cancel_work(queue, work);
|
|
}
|
|
rt_exit_critical();
|
|
|
|
return RT_EOK;
|
|
}
|
|
|
|
#ifdef RT_USING_SYSTEM_WORKQUEUE
|
|
|
|
static struct rt_workqueue *sys_workq; /* system work queue */
|
|
|
|
/**
|
|
* @brief Submit a work item to the system work queue with a delay.
|
|
*
|
|
* @param work is a pointer to the work item object.
|
|
*
|
|
* @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)
|
|
*
|
|
* @return RT_EOK Success.
|
|
* -RT_ERROR The ticks parameter is invalid.
|
|
*/
|
|
rt_err_t rt_work_submit(struct rt_work *work, rt_tick_t ticks)
|
|
{
|
|
return rt_workqueue_submit_work(sys_workq, work, ticks);
|
|
}
|
|
|
|
/**
|
|
* @brief Submit a work item to the system work queue without delay. This work item will be executed after the current work item.
|
|
*
|
|
* @param work is a pointer to the work item object.
|
|
*
|
|
* @return RT_EOK Success.
|
|
*/
|
|
rt_err_t rt_work_urgent(struct rt_work *work)
|
|
{
|
|
return rt_workqueue_urgent_work(sys_workq, work);
|
|
}
|
|
|
|
/**
|
|
* @brief Cancel a work item in the system work queue.
|
|
*
|
|
* @param work is a pointer to the work item object.
|
|
*
|
|
* @return RT_EOK Success.
|
|
* -RT_EBUSY This work item is executing.
|
|
*/
|
|
rt_err_t rt_work_cancel(struct rt_work *work)
|
|
{
|
|
return rt_workqueue_cancel_work(sys_workq, work);
|
|
}
|
|
|
|
static int rt_work_sys_workqueue_init(void)
|
|
{
|
|
if (sys_workq != RT_NULL)
|
|
return RT_EOK;
|
|
|
|
sys_workq = rt_workqueue_create("sys workq", RT_SYSTEM_WORKQUEUE_STACKSIZE,
|
|
RT_SYSTEM_WORKQUEUE_PRIORITY);
|
|
RT_ASSERT(sys_workq != RT_NULL);
|
|
|
|
return RT_EOK;
|
|
}
|
|
INIT_PREV_EXPORT(rt_work_sys_workqueue_init);
|
|
#endif /* RT_USING_SYSTEM_WORKQUEUE */
|
|
#endif /* RT_USING_HEAP */
|