This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 2e1cef47ab6 aio: use list_node for the AIO container lists
2e1cef47ab6 is described below
commit 2e1cef47ab61d6501f96de57cdd01b93b54111db
Author: ouyangxiangzhen <[email protected]>
AuthorDate: Mon Oct 12 11:08:15 2026 +0800
aio: use list_node for the AIO container lists
Replace the dq_queue_t/dq_entry_t based container lists (g_aio_pending,
the free list and the aio_cleanup() local queue) with struct list_node.
The list_t primitives give branch-free O(1) link/unlink on the hot
submit/complete path where every aio_read()/aio_write()/aio_fsync() takes
and returns a container, an O(1) membership test via list_in_list(), and
safe iteration via list_for_every_entry_safe(). The lists are statically
initialized with LIST_INITIAL_VALUE() so they are valid even before
aio_initialize() runs.
Signed-off-by: ouyangxiangzhen <[email protected]>
Signed-off-by: v-liuchenxu3 <[email protected]>
---
fs/aio/aio.h | 6 +++---
fs/aio/aio_cancel.c | 44 ++++++++++++++++++++++----------------------
fs/aio/aio_initialize.c | 11 ++++++-----
fs/aio/aioc_contain.c | 4 ++--
4 files changed, 33 insertions(+), 32 deletions(-)
diff --git a/fs/aio/aio.h b/fs/aio/aio.h
index aeb63ef845b..f6fc21eb4aa 100644
--- a/fs/aio/aio.h
+++ b/fs/aio/aio.h
@@ -31,7 +31,7 @@
#include <string.h>
#include <aio.h>
-#include <nuttx/queue.h>
+#include <nuttx/list.h>
#include <nuttx/wqueue.h>
#ifdef CONFIG_FS_AIO
@@ -60,7 +60,7 @@
struct file;
struct aio_container_s
{
- dq_entry_t aioc_link; /* Supports a doubly linked list */
+ struct list_node aioc_link; /* Supports a doubly linked list */
FAR struct aiocb *aioc_aiocbp; /* The contained AIO control block */
FAR struct file *aioc_filep; /* File structure to use with the I/O */
struct work_s aioc_work; /* Used to defer I/O to the work thread */
@@ -87,7 +87,7 @@ extern "C"
* lock on this list in order to access the list.
*/
-extern dq_queue_t g_aio_pending;
+extern struct list_node g_aio_pending;
/****************************************************************************
* Public Function Prototypes
diff --git a/fs/aio/aio_cancel.c b/fs/aio/aio_cancel.c
index bff7a75fb17..8ba970df687 100644
--- a/fs/aio/aio_cancel.c
+++ b/fs/aio/aio_cancel.c
@@ -85,8 +85,8 @@
int aio_cancel(int fildes, FAR struct aiocb *aiocbp)
{
- FAR struct aio_container_s *aioc;
- FAR struct aio_container_s *next;
+ FAR struct aio_container_s *aioc = NULL;
+ FAR struct aio_container_s *temp;
FAR struct file *filep;
pid_t pid;
@@ -119,9 +119,15 @@ int aio_cancel(int fildes, FAR struct aiocb *aiocbp)
{
/* No.. Find the container for this AIO control block */
- for (aioc = (FAR struct aio_container_s *)g_aio_pending.head;
- aioc && aioc->aioc_aiocbp != aiocbp;
- aioc = (FAR struct aio_container_s *)aioc->aioc_link.flink);
+ list_for_every_entry(&g_aio_pending, temp, struct aio_container_s,
+ aioc_link)
+ {
+ if (temp->aioc_aiocbp == aiocbp)
+ {
+ aioc = temp;
+ break;
+ }
+ }
/* Did we find a container for this fildes? We should; the
* aio_result says that the transfer is pending. If not we return
@@ -172,12 +178,9 @@ int aio_cancel(int fildes, FAR struct aiocb *aiocbp)
{
/* No aiocbp.. cancel all outstanding I/O for the fildes */
- for (aioc = (FAR struct aio_container_s *)g_aio_pending.head;
- aioc;
- aioc = next)
+ list_for_every_entry_safe(&g_aio_pending, aioc, temp,
+ struct aio_container_s, aioc_link)
{
- next = (FAR struct aio_container_s *)aioc->aioc_link.flink;
-
if (aioc->aioc_aiocbp->aio_fildes != fildes)
{
continue;
@@ -258,10 +261,10 @@ int aio_cancel(int fildes, FAR struct aiocb *aiocbp)
void aio_cleanup(pid_t pid)
{
FAR struct aio_container_s *aioc;
- FAR struct aio_container_s *next;
- dq_queue_t queue;
+ FAR struct aio_container_s *temp;
+ struct list_node queue;
- dq_init(&queue);
+ list_initialize(&queue);
/* Take ownership of every container submitted by the exiting task: mark
* it so aioc_decant() will not touch it, detach it from the pending list
@@ -271,20 +274,17 @@ void aio_cleanup(pid_t pid)
aio_lock();
- for (aioc = (FAR struct aio_container_s *)g_aio_pending.head;
- aioc;
- aioc = next)
+ list_for_every_entry_safe(&g_aio_pending, aioc, temp,
+ struct aio_container_s, aioc_link)
{
- next = (FAR struct aio_container_s *)aioc->aioc_link.flink;
-
if (aioc->aioc_pid != pid)
{
continue;
}
aioc->aioc_pid = INVALID_PROCESS_ID;
- dq_rem(&aioc->aioc_link, &g_aio_pending);
- dq_addlast(&aioc->aioc_link, &queue);
+ list_delete(&aioc->aioc_link);
+ list_add_tail(&queue, &aioc->aioc_link);
}
aio_unlock();
@@ -299,8 +299,8 @@ void aio_cleanup(pid_t pid)
* of the ownership marker.
*/
- while ((aioc = (FAR struct aio_container_s *)
- dq_remfirst(&queue)) != NULL)
+ while ((aioc = list_remove_head_type(&queue, struct aio_container_s,
+ aioc_link)) != NULL)
{
work_cancel_sync(LPWORK, &aioc->aioc_work);
file_put(aioc->aioc_filep);
diff --git a/fs/aio/aio_initialize.c b/fs/aio/aio_initialize.c
index 8364cbc33de..4816366c52f 100644
--- a/fs/aio/aio_initialize.c
+++ b/fs/aio/aio_initialize.c
@@ -47,7 +47,7 @@ static struct aio_container_s g_aioc_alloc[CONFIG_FS_NAIOC];
/* This is a list of free AIO containers */
-static dq_queue_t g_aioc_free;
+static struct list_node g_aioc_free = LIST_INITIAL_VALUE(g_aioc_free);
/* This counting semaphore tracks the number of free AIO containers */
@@ -68,7 +68,7 @@ static rmutex_t g_aio_lock = NXRMUTEX_INITIALIZER;
* lock on this list in order to access the list.
*/
-dq_queue_t g_aio_pending;
+struct list_node g_aio_pending = LIST_INITIAL_VALUE(g_aio_pending);
/****************************************************************************
* Public Functions
@@ -98,7 +98,7 @@ void aio_initialize(void)
{
/* Add the container to the free list */
- dq_addlast(&g_aioc_alloc[i].aioc_link, &g_aioc_free);
+ list_add_tail(&g_aioc_free, &g_aioc_alloc[i].aioc_link);
}
}
@@ -165,7 +165,8 @@ FAR struct aio_container_s *aioc_alloc(void)
ret = aio_lock();
if (ret >= 0)
{
- aioc = (FAR struct aio_container_s *)dq_remfirst(&g_aioc_free);
+ aioc = list_remove_head_type(&g_aioc_free, struct aio_container_s,
+ aioc_link);
aio_unlock();
DEBUGASSERT(aioc);
@@ -209,7 +210,7 @@ void aioc_free(FAR struct aio_container_s *aioc)
}
while (ret < 0);
- dq_addlast(&aioc->aioc_link, &g_aioc_free);
+ list_add_tail(&g_aioc_free, &aioc->aioc_link);
aio_unlock();
/* The post the counting semaphore, announcing the availability of the
diff --git a/fs/aio/aioc_contain.c b/fs/aio/aioc_contain.c
index 0efe46d7977..415fbb585f5 100644
--- a/fs/aio/aioc_contain.c
+++ b/fs/aio/aioc_contain.c
@@ -109,7 +109,7 @@ FAR struct aio_container_s *aio_contain(FAR struct aiocb
*aiocbp)
goto err_putfilep;
}
- dq_addlast(&aioc->aioc_link, &g_aio_pending);
+ list_add_tail(&g_aio_pending, &aioc->aioc_link);
aio_unlock();
return aioc;
@@ -161,7 +161,7 @@ FAR struct aiocb *aioc_decant(FAR struct aio_container_s
*aioc)
if (aioc->aioc_pid != INVALID_PROCESS_ID)
{
- dq_rem(&aioc->aioc_link, &g_aio_pending);
+ list_delete(&aioc->aioc_link);
/* De-cant the AIO control block and return the container to the
* free list.