This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit eb6fe17baadfbd909a396dfc8f4ec30c0ddc52bd
Author: chao an <[email protected]>
AuthorDate: Wed Mar 6 14:00:48 2024 +0800

    nuttx/list/queue: add helper macro list/sq/dq_is_singular()
    
    add helper macro list/sq/dq_is_singular() to tests whether a list has just 
one entry.
    
    Signed-off-by: chao an <[email protected]>
---
 include/nuttx/list.h  | 7 ++++---
 include/nuttx/queue.h | 8 ++++++++
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/include/nuttx/list.h b/include/nuttx/list.h
index b3b4309374..cadbccc335 100644
--- a/include/nuttx/list.h
+++ b/include/nuttx/list.h
@@ -69,9 +69,10 @@
 #define LIST_INITIAL_VALUE(list) { &(list), &(list) }
 #define LIST_INITIAL_CLEARED_VALUE { NULL, NULL }
 
-#define list_in_list(item) ((item)->prev != NULL)
-#define list_is_empty(list) ((list)->next == list)
-#define list_is_clear(list) ((list)->next == NULL)
+#define list_in_list(item)     ((item)->prev != NULL)
+#define list_is_empty(list)    ((list)->next == list)
+#define list_is_clear(list)    ((list)->next == NULL)
+#define list_is_singular(list) ((list)->next == (list)->prev)
 
 #define list_initialize(list) \
   do \
diff --git a/include/nuttx/queue.h b/include/nuttx/queue.h
index 159f548e49..6a07d6a4dc 100644
--- a/include/nuttx/queue.h
+++ b/include/nuttx/queue.h
@@ -290,6 +290,14 @@
 #define dq_inqueue(p, q) \
       ((p)->flink || dq_tail(q) == (p))
 
+/* sq/dq_is_singular - tests whether a list has just one entry.  */
+
+#define sq_is_singular(q) \
+      (!sq_empty(q) && (q)->head->flink == NULL)
+
+#define dq_is_singular(q) \
+      (!dq_empty(q) && (q)->head->flink == NULL)
+
 /****************************************************************************
  * Public Type Definitions
  ****************************************************************************/

Reply via email to