feat(<scope>): The synchronization operation of async is disabled by default.
1.The synchronization operation of async is essentially a trick, so it is not enabled by default。 2.Optimize the inter-lock operation. For instance, before operating on a linked list, it is necessary to first determine whether the linked list is in use (during active operation, the probability of not using it is too low, resulting in invalid judgments and prolonging the lock time).
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
menu "Async options"
|
||||
|
||||
endmenu
|
||||
@@ -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.
|
||||
@@ -16,7 +16,7 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include <mr-X/async/mr_async.h>
|
||||
#include <mr-X/mr_async.h>
|
||||
#include <mr-X/mr_clock.h>
|
||||
#include <mr-X/mr_fifo.h>
|
||||
#include <mr-X/mr_hook.h>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* @date 2024-09-06 MacRsh First version
|
||||
*/
|
||||
|
||||
#include <mr-X/async/mr_async.h>
|
||||
#include <mr-X/mr_async.h>
|
||||
#if defined(MR_USE_ASYNC)
|
||||
#include <mr-X/mr_spinlock.h>
|
||||
#include <libc/mr_malloc.h>
|
||||
@@ -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);
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user