diff --git a/include/mr-X/Kconfig b/include/mr-X/Kconfig index 2ac1dc8..eb39de9 100644 --- a/include/mr-X/Kconfig +++ b/include/mr-X/Kconfig @@ -86,8 +86,9 @@ config MR_USE_ASYNC bool "Use async" default y -if MR_USE_ASYNC -rsource "async/Kconfig" -endif +config MR_USE_ASYNC_SYNC + depends on MR_USE_ASYNC + bool "Use async sync" + default n endmenu diff --git a/include/mr-X/async/Kconfig b/include/mr-X/async/Kconfig deleted file mode 100644 index ce63270..0000000 --- a/include/mr-X/async/Kconfig +++ /dev/null @@ -1,3 +0,0 @@ -menu "Async options" - -endmenu diff --git a/include/mr-X/async/mr_async.h b/include/mr-X/mr_async.h similarity index 95% rename from include/mr-X/async/mr_async.h rename to include/mr-X/mr_async.h index 53849bc..117b456 100644 --- a/include/mr-X/async/mr_async.h +++ b/include/mr-X/mr_async.h @@ -138,6 +138,22 @@ mr_async_t *mr_async_create(mr_async_entry_t *entry, void *param); */ mr_err_t mr_async_del(mr_async_t *async); +/** + * @brief This macro function runs an async. + * + * @param _async The async. + * @param _queue The workqueue. + */ +#define mr_async_run(_async, _queue) \ + mr_workqueue_work(_queue, &(_async)->work) + +/** + * @brief This macro function checks if an async is waiting. + * + * @param _async The async. + */ +#define MR_ASYNC_IS_WAITING(_async) (!mr_list_is_empty(&(_async)->list)) + /** * @brief This function cancels an async. * @@ -148,15 +164,6 @@ mr_err_t mr_async_del(mr_async_t *async); */ mr_err_t mr_async_cancel(mr_async_t *async); -/** - * @brief This macro function runs an async. - * - * @param _async The async. - * @param _queue The workqueue. - */ -#define mr_async_run(_async, _queue) \ - mr_workqueue_work(_queue, &(_async)->work) - /** * @brief This macro function waits for an async. * @@ -166,6 +173,7 @@ mr_err_t mr_async_cancel(mr_async_t *async); #define mr_async_wait_async(_async, _wait_async) \ mr_await_wait(&(_wait_async)->await, _async) +#if defined(MR_USE_ASYNC_SYNC) /** * @brief This macro function begins an async. * @@ -187,29 +195,6 @@ mr_err_t mr_async_cancel(mr_async_t *async); } \ while (0) -/** - * @brief This macro function checks if an async is waiting. - * - * @param _async The async. - */ -#define MR_ASYNC_IS_WAITING(_async) (!mr_list_is_empty(&(_async)->list)) - -/** - * @brief This macro function suspends an async. - * - * @param _async The async. - * - * @note It can only be used between 'mr_async_begin' and 'mr_async_end'. - */ -#define mr_async_suspend(_async) mr_work_cancel(&(_async)->work) - -/** - * @brief This macro function resumes an async. - * - * @param _async The async. - */ -#define mr_async_resume(_async) mr_work_schedule(&(_async)->work) - /** * @brief This macro function yields an async. * @@ -219,7 +204,7 @@ mr_err_t mr_async_cancel(mr_async_t *async); */ #define mr_async_yield(_async) \ do { \ - mr_async_resume(_async); \ + mr_work_schedule(&(_async)->work); \ (_async)->label = __LINE__; \ return; \ case __LINE__:; \ @@ -282,6 +267,7 @@ mr_err_t mr_async_cancel(mr_async_t *async); mr_async_cancel(_async); \ } \ } while (0) +#endif /* defined(MR_USE_ASYNC_SYNC) */ /** * @brief This function gets an async. diff --git a/include/mr_x.h b/include/mr_x.h index 9c76481..0a5dffb 100644 --- a/include/mr_x.h +++ b/include/mr_x.h @@ -16,7 +16,7 @@ * @{ */ -#include +#include #include #include #include diff --git a/kernel/async/async.c b/kernel/async.c similarity index 97% rename from kernel/async/async.c rename to kernel/async.c index 909a503..ee6cea4 100644 --- a/kernel/async/async.c +++ b/kernel/async.c @@ -6,7 +6,7 @@ * @date 2024-09-06 MacRsh First version */ -#include +#include #if defined(MR_USE_ASYNC) #include #include @@ -153,7 +153,7 @@ mr_err_t mr_await_complete(mr_await_t *await) { /* Remove async from waiting list */ mr_list_del(&async->list); - /* Force resume async */ + /* Force resume async(it might be running a timer) */ mr_work_cancel(&async->work); mr_work_schedule(&async->work); } @@ -254,11 +254,8 @@ static void async_remove(mr_async_t *async) { /* Lock */ mask = mr_spinlock_lock_irqsave(&__lock); - /* Check if async is removed */ - if (!mr_list_is_empty(&async->list)) { - /* Remove async from waiting list */ - mr_list_del(&async->list); - } + /* Remove async from waiting list */ + mr_list_del(&async->list); /* Unlock */ mr_spinlock_unlock_irqrestore(&__lock, mask); diff --git a/kernel/timer.c b/kernel/timer.c index 2b7aefb..ae4239a 100644 --- a/kernel/timer.c +++ b/kernel/timer.c @@ -75,11 +75,8 @@ static void timer_remove(mr_timer_t *timer) { /* Lock */ mask = mr_spinlock_lock_irqsave(&__lock); - /* Check if timer is removed */ - if (!mr_list_is_empty(&timer->list)) { - /* Remove timer from timing list */ - mr_list_del(&timer->list); - } + /* Remove timer from timing list */ + mr_list_del(&timer->list); /* Unlock */ mr_spinlock_unlock_irqrestore(&__lock, mask); @@ -174,9 +171,7 @@ mr_err_t mr_timer_tick_set(mr_timer_t *timer, mr_tick_t tick) { mask = mr_spinlock_lock_irqsave(&__lock); /* Remove timer from timing list */ - if (!mr_list_is_empty(&timer->list)) { - mr_list_del(&timer->list); - } + mr_list_del(&timer->list); /* Set init tick */ timer->itick = tick; diff --git a/kernel/workqueue.c b/kernel/workqueue.c index b9f2c33..690f5fd 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -543,11 +543,8 @@ static void work_remove(mr_work_t *work) { /* Lock */ mask = mr_spinlock_lock_irqsave(&__lock); - /* Check if work is running */ - if (MR_WORK_IS_RUNNING(work)) { - /* Remove work from running list */ - mr_list_del(&work->list); - } + /* Remove work from running list */ + mr_list_del(&work->list); /* Unlock */ mr_spinlock_unlock_irqrestore(&__lock, mask);