2019-01-27 11:56:25 -06:00
|
|
|
/****************************************************************************
|
|
|
|
|
* include/nuttx/list.h
|
|
|
|
|
*
|
2024-10-02 15:59:15 +02:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
* SPDX-FileCopyrightText: 2008 Travis Geiselbrecht. All rights reserved.
|
|
|
|
|
* SPDX-FileContributor: Travis Geiselbrecht <geist@foobox.com>
|
|
|
|
|
*
|
2023-08-23 05:15:29 +08:00
|
|
|
* Extracted from logic originally written by Travis Geiselbrecht and
|
|
|
|
|
* released under a public domain license. Re-released here under the 3-
|
|
|
|
|
* clause BSD license by Pinecone, Inc.
|
2020-08-23 00:36:57 +08:00
|
|
|
*
|
2023-08-23 05:15:29 +08:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
|
* are met:
|
|
|
|
|
*
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
|
* distribution.
|
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
|
* without specific prior written permission.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
2019-01-27 11:56:25 -06:00
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#ifndef __INCLUDE_NUTTX_LIST_H
|
|
|
|
|
#define __INCLUDE_NUTTX_LIST_H
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Included Files
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Pre-processor Definitions
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
nuttx/list: rename container_of to list_container_of from public header
Use private naming to avoid conflicts with user applications
In file included from libuv/src/unix/internal.h:25,
from libuv/src/unix/udp.c:23:
libuv/src/uv-common.h:57: warning: "container_of" redefined
57 | #define container_of(ptr, type, member) \
|
In file included from nuttx/include/nuttx/list.h:47,
from nuttx/include/nuttx/tls.h:40,
from nuttx/include/nuttx/sched.h:48,
from nuttx/include/nuttx/arch.h:87,
from nuttx/include/nuttx/userspace.h:35,
from nuttx/include/nuttx/mm/mm.h:30,
from nuttx/include/nuttx/kmalloc.h:34,
from nuttx/include/nuttx/lib/lib.h:31,
from nuttx/include/stdio.h:35,
from apps/system/libuv/libuv/include/uv.h:59,
from libuv/src/unix/udp.c:22:
nuttx/include/nuttx/nuttx.h:48: note: this is the location of the previous definition
48 | #define container_of(ptr, type, member) \
|
Signed-off-by: chao an <anchao@lixiang.com>
2024-02-29 10:19:49 +08:00
|
|
|
/* Name: list_container_of
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* Cast a member of a structure out to get the address of the containing
|
|
|
|
|
* structure
|
|
|
|
|
*
|
|
|
|
|
* Arguments:
|
|
|
|
|
* ptr - The pointer to the member.
|
|
|
|
|
* type - The type of the container struct this is embedded in.
|
|
|
|
|
* member - The name of the member within the struct.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#define list_container_of(ptr, type, member) \
|
|
|
|
|
((type *)((uintptr_t)(ptr) - offsetof(type, member)))
|
|
|
|
|
|
2019-01-27 11:56:25 -06:00
|
|
|
#define LIST_INITIAL_VALUE(list) { &(list), &(list) }
|
|
|
|
|
#define LIST_INITIAL_CLEARED_VALUE { NULL, NULL }
|
2019-01-29 07:37:22 -06:00
|
|
|
|
2024-03-06 14:00:48 +08:00
|
|
|
#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)
|
2022-08-25 14:32:38 +08:00
|
|
|
|
|
|
|
|
#define list_initialize(list) \
|
|
|
|
|
do \
|
|
|
|
|
{ \
|
2022-10-03 22:00:20 +08:00
|
|
|
FAR struct list_node *__list = (list); \
|
|
|
|
|
__list->prev = __list->next = __list; \
|
2022-08-25 14:32:38 +08:00
|
|
|
} \
|
|
|
|
|
while(0)
|
|
|
|
|
|
|
|
|
|
#define list_clear_node(item) \
|
|
|
|
|
do \
|
|
|
|
|
{ \
|
2022-10-03 22:00:20 +08:00
|
|
|
FAR struct list_node *__item = (item); \
|
|
|
|
|
__item->prev = __item->next = NULL; \
|
2022-08-25 14:32:38 +08:00
|
|
|
} \
|
|
|
|
|
while (0)
|
|
|
|
|
|
2024-06-11 23:23:44 +08:00
|
|
|
#define list_is_head(list, item) ((list)->next == (item))
|
|
|
|
|
#define list_is_tail(list, item) ((list)->prev == (item))
|
2022-08-25 14:32:38 +08:00
|
|
|
#define list_peek_head(list) ((list)->next != (list) ? (list)->next : NULL)
|
|
|
|
|
#define list_peek_tail(list) ((list)->prev != (list) ? (list)->prev : NULL)
|
|
|
|
|
|
|
|
|
|
#define list_prev(list, item) ((item)->prev != (list) ? (item)->prev : NULL)
|
|
|
|
|
#define list_prev_wrap(list, item) \
|
|
|
|
|
((item)->prev != (list) ? (item)->prev : \
|
|
|
|
|
(item)->prev->prev != (list) ? (item)->prev->prev : NULL)
|
|
|
|
|
|
|
|
|
|
#define list_next(list, item) ((item)->next != (list) ? (item)->next : NULL)
|
|
|
|
|
#define list_next_wrap(list, item) \
|
|
|
|
|
((item)->next != (list) ? (item)->next : \
|
|
|
|
|
(item)->next->next != (list) ? (item)->next->next : NULL)
|
2019-01-27 11:56:25 -06:00
|
|
|
|
nuttx/list: rename container_of to list_container_of from public header
Use private naming to avoid conflicts with user applications
In file included from libuv/src/unix/internal.h:25,
from libuv/src/unix/udp.c:23:
libuv/src/uv-common.h:57: warning: "container_of" redefined
57 | #define container_of(ptr, type, member) \
|
In file included from nuttx/include/nuttx/list.h:47,
from nuttx/include/nuttx/tls.h:40,
from nuttx/include/nuttx/sched.h:48,
from nuttx/include/nuttx/arch.h:87,
from nuttx/include/nuttx/userspace.h:35,
from nuttx/include/nuttx/mm/mm.h:30,
from nuttx/include/nuttx/kmalloc.h:34,
from nuttx/include/nuttx/lib/lib.h:31,
from nuttx/include/stdio.h:35,
from apps/system/libuv/libuv/include/uv.h:59,
from libuv/src/unix/udp.c:22:
nuttx/include/nuttx/nuttx.h:48: note: this is the location of the previous definition
48 | #define container_of(ptr, type, member) \
|
Signed-off-by: chao an <anchao@lixiang.com>
2024-02-29 10:19:49 +08:00
|
|
|
#define list_entry(ptr, type, member) list_container_of(ptr, type, member)
|
|
|
|
|
#define list_first_entry(list, type, member) list_container_of((list)->next, type, member)
|
|
|
|
|
#define list_last_entry(list, type, member) list_container_of((list)->prev, type, member)
|
|
|
|
|
#define list_next_entry(list, type, member) list_container_of((list)->member.next, type, member)
|
|
|
|
|
#define list_prev_entry(list, type, member) list_container_of((list)->member.prev, type, member)
|
2022-08-13 16:35:59 +08:00
|
|
|
|
2022-08-25 14:32:38 +08:00
|
|
|
#define list_add_after(entry, new_entry) list_add_head(entry, new_entry)
|
|
|
|
|
#define list_add_head(list, item) \
|
|
|
|
|
do \
|
|
|
|
|
{ \
|
2022-10-03 22:00:20 +08:00
|
|
|
FAR struct list_node *__list = (list); \
|
|
|
|
|
FAR struct list_node *__item = (item); \
|
|
|
|
|
__item->next = __list->next; \
|
|
|
|
|
__item->prev = __list; \
|
|
|
|
|
__list->next->prev = __item; \
|
|
|
|
|
__list->next = __item; \
|
2022-08-25 14:32:38 +08:00
|
|
|
} \
|
|
|
|
|
while (0)
|
|
|
|
|
|
|
|
|
|
#define list_add_before(entry, new_entry) list_add_tail(entry, new_entry)
|
|
|
|
|
#define list_add_tail(list, item) \
|
|
|
|
|
do \
|
|
|
|
|
{ \
|
2022-10-03 22:00:20 +08:00
|
|
|
FAR struct list_node *__list = (list); \
|
|
|
|
|
FAR struct list_node *__item = (item); \
|
|
|
|
|
__item->prev = __list->prev; \
|
|
|
|
|
__item->next = __list; \
|
|
|
|
|
__list->prev->next = __item; \
|
|
|
|
|
__list->prev = __item; \
|
2022-08-25 14:32:38 +08:00
|
|
|
} \
|
|
|
|
|
while (0)
|
|
|
|
|
|
|
|
|
|
#define list_delete(item) \
|
|
|
|
|
do \
|
|
|
|
|
{ \
|
2022-10-03 22:00:20 +08:00
|
|
|
FAR struct list_node *__item = (item); \
|
|
|
|
|
__item->next->prev = __item->prev; \
|
|
|
|
|
__item->prev->next = __item->next; \
|
|
|
|
|
__item->prev = __item->next = NULL; \
|
2022-08-25 14:32:38 +08:00
|
|
|
} \
|
|
|
|
|
while (0)
|
|
|
|
|
|
2023-08-11 18:28:10 +08:00
|
|
|
#define list_delete_init(item) \
|
|
|
|
|
do \
|
|
|
|
|
{ \
|
|
|
|
|
list_delete(item); \
|
|
|
|
|
list_initialize(item); \
|
|
|
|
|
} \
|
|
|
|
|
while (0)
|
|
|
|
|
|
2022-10-03 22:00:20 +08:00
|
|
|
#define list_remove_head_type(list, type, member) \
|
|
|
|
|
({ \
|
|
|
|
|
FAR struct list_node *__node = list_remove_head(list); \
|
|
|
|
|
FAR type *__t = NULL; \
|
|
|
|
|
if(__node) \
|
|
|
|
|
{ \
|
nuttx/list: rename container_of to list_container_of from public header
Use private naming to avoid conflicts with user applications
In file included from libuv/src/unix/internal.h:25,
from libuv/src/unix/udp.c:23:
libuv/src/uv-common.h:57: warning: "container_of" redefined
57 | #define container_of(ptr, type, member) \
|
In file included from nuttx/include/nuttx/list.h:47,
from nuttx/include/nuttx/tls.h:40,
from nuttx/include/nuttx/sched.h:48,
from nuttx/include/nuttx/arch.h:87,
from nuttx/include/nuttx/userspace.h:35,
from nuttx/include/nuttx/mm/mm.h:30,
from nuttx/include/nuttx/kmalloc.h:34,
from nuttx/include/nuttx/lib/lib.h:31,
from nuttx/include/stdio.h:35,
from apps/system/libuv/libuv/include/uv.h:59,
from libuv/src/unix/udp.c:22:
nuttx/include/nuttx/nuttx.h:48: note: this is the location of the previous definition
48 | #define container_of(ptr, type, member) \
|
Signed-off-by: chao an <anchao@lixiang.com>
2024-02-29 10:19:49 +08:00
|
|
|
__t = list_container_of(__node, type, member); \
|
2022-10-03 22:00:20 +08:00
|
|
|
} \
|
|
|
|
|
__t; \
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
#define list_remove_tail_type(list, type, member) \
|
|
|
|
|
({ \
|
|
|
|
|
FAR struct list_node *__node = list_remove_tail(list); \
|
|
|
|
|
FAR type *__t = NULL; \
|
|
|
|
|
if(__node) \
|
|
|
|
|
{ \
|
nuttx/list: rename container_of to list_container_of from public header
Use private naming to avoid conflicts with user applications
In file included from libuv/src/unix/internal.h:25,
from libuv/src/unix/udp.c:23:
libuv/src/uv-common.h:57: warning: "container_of" redefined
57 | #define container_of(ptr, type, member) \
|
In file included from nuttx/include/nuttx/list.h:47,
from nuttx/include/nuttx/tls.h:40,
from nuttx/include/nuttx/sched.h:48,
from nuttx/include/nuttx/arch.h:87,
from nuttx/include/nuttx/userspace.h:35,
from nuttx/include/nuttx/mm/mm.h:30,
from nuttx/include/nuttx/kmalloc.h:34,
from nuttx/include/nuttx/lib/lib.h:31,
from nuttx/include/stdio.h:35,
from apps/system/libuv/libuv/include/uv.h:59,
from libuv/src/unix/udp.c:22:
nuttx/include/nuttx/nuttx.h:48: note: this is the location of the previous definition
48 | #define container_of(ptr, type, member) \
|
Signed-off-by: chao an <anchao@lixiang.com>
2024-02-29 10:19:49 +08:00
|
|
|
__t = list_container_of(__node, type, member); \
|
2022-10-03 22:00:20 +08:00
|
|
|
} \
|
|
|
|
|
__t; \
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
#define list_peek_head_type(list, type, member) \
|
|
|
|
|
({ \
|
|
|
|
|
FAR struct list_node *__node = list_peek_head(list); \
|
|
|
|
|
FAR type *__t = NULL; \
|
|
|
|
|
if(__node) \
|
|
|
|
|
{ \
|
nuttx/list: rename container_of to list_container_of from public header
Use private naming to avoid conflicts with user applications
In file included from libuv/src/unix/internal.h:25,
from libuv/src/unix/udp.c:23:
libuv/src/uv-common.h:57: warning: "container_of" redefined
57 | #define container_of(ptr, type, member) \
|
In file included from nuttx/include/nuttx/list.h:47,
from nuttx/include/nuttx/tls.h:40,
from nuttx/include/nuttx/sched.h:48,
from nuttx/include/nuttx/arch.h:87,
from nuttx/include/nuttx/userspace.h:35,
from nuttx/include/nuttx/mm/mm.h:30,
from nuttx/include/nuttx/kmalloc.h:34,
from nuttx/include/nuttx/lib/lib.h:31,
from nuttx/include/stdio.h:35,
from apps/system/libuv/libuv/include/uv.h:59,
from libuv/src/unix/udp.c:22:
nuttx/include/nuttx/nuttx.h:48: note: this is the location of the previous definition
48 | #define container_of(ptr, type, member) \
|
Signed-off-by: chao an <anchao@lixiang.com>
2024-02-29 10:19:49 +08:00
|
|
|
__t = list_container_of(__node, type, member); \
|
2022-10-03 22:00:20 +08:00
|
|
|
} \
|
|
|
|
|
__t; \
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
#define list_peek_tail_type(list, type, member) \
|
|
|
|
|
({ \
|
|
|
|
|
FAR struct list_node *__node = list_peek_tail(list); \
|
|
|
|
|
FAR type *__t = NULL; \
|
|
|
|
|
if(__node) \
|
|
|
|
|
{ \
|
nuttx/list: rename container_of to list_container_of from public header
Use private naming to avoid conflicts with user applications
In file included from libuv/src/unix/internal.h:25,
from libuv/src/unix/udp.c:23:
libuv/src/uv-common.h:57: warning: "container_of" redefined
57 | #define container_of(ptr, type, member) \
|
In file included from nuttx/include/nuttx/list.h:47,
from nuttx/include/nuttx/tls.h:40,
from nuttx/include/nuttx/sched.h:48,
from nuttx/include/nuttx/arch.h:87,
from nuttx/include/nuttx/userspace.h:35,
from nuttx/include/nuttx/mm/mm.h:30,
from nuttx/include/nuttx/kmalloc.h:34,
from nuttx/include/nuttx/lib/lib.h:31,
from nuttx/include/stdio.h:35,
from apps/system/libuv/libuv/include/uv.h:59,
from libuv/src/unix/udp.c:22:
nuttx/include/nuttx/nuttx.h:48: note: this is the location of the previous definition
48 | #define container_of(ptr, type, member) \
|
Signed-off-by: chao an <anchao@lixiang.com>
2024-02-29 10:19:49 +08:00
|
|
|
__t = list_container_of(__node, type, member); \
|
2022-10-03 22:00:20 +08:00
|
|
|
} \
|
|
|
|
|
__t; \
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
#define list_prev_type(list, item, type, member) \
|
|
|
|
|
({ \
|
|
|
|
|
FAR struct list_node *__node = list_prev(list, item); \
|
|
|
|
|
FAR type *__t = NULL; \
|
|
|
|
|
if(__node) \
|
|
|
|
|
{ \
|
nuttx/list: rename container_of to list_container_of from public header
Use private naming to avoid conflicts with user applications
In file included from libuv/src/unix/internal.h:25,
from libuv/src/unix/udp.c:23:
libuv/src/uv-common.h:57: warning: "container_of" redefined
57 | #define container_of(ptr, type, member) \
|
In file included from nuttx/include/nuttx/list.h:47,
from nuttx/include/nuttx/tls.h:40,
from nuttx/include/nuttx/sched.h:48,
from nuttx/include/nuttx/arch.h:87,
from nuttx/include/nuttx/userspace.h:35,
from nuttx/include/nuttx/mm/mm.h:30,
from nuttx/include/nuttx/kmalloc.h:34,
from nuttx/include/nuttx/lib/lib.h:31,
from nuttx/include/stdio.h:35,
from apps/system/libuv/libuv/include/uv.h:59,
from libuv/src/unix/udp.c:22:
nuttx/include/nuttx/nuttx.h:48: note: this is the location of the previous definition
48 | #define container_of(ptr, type, member) \
|
Signed-off-by: chao an <anchao@lixiang.com>
2024-02-29 10:19:49 +08:00
|
|
|
__t = list_container_of(__node, type, member); \
|
2022-10-03 22:00:20 +08:00
|
|
|
} \
|
|
|
|
|
__t; \
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
#define list_prev_wrap_type(list, item, type, member) \
|
|
|
|
|
({ \
|
|
|
|
|
FAR struct list_node *__node = list_prev_wrap(list, item); \
|
|
|
|
|
FAR type *__t = NULL; \
|
|
|
|
|
if(__node) \
|
|
|
|
|
{ \
|
nuttx/list: rename container_of to list_container_of from public header
Use private naming to avoid conflicts with user applications
In file included from libuv/src/unix/internal.h:25,
from libuv/src/unix/udp.c:23:
libuv/src/uv-common.h:57: warning: "container_of" redefined
57 | #define container_of(ptr, type, member) \
|
In file included from nuttx/include/nuttx/list.h:47,
from nuttx/include/nuttx/tls.h:40,
from nuttx/include/nuttx/sched.h:48,
from nuttx/include/nuttx/arch.h:87,
from nuttx/include/nuttx/userspace.h:35,
from nuttx/include/nuttx/mm/mm.h:30,
from nuttx/include/nuttx/kmalloc.h:34,
from nuttx/include/nuttx/lib/lib.h:31,
from nuttx/include/stdio.h:35,
from apps/system/libuv/libuv/include/uv.h:59,
from libuv/src/unix/udp.c:22:
nuttx/include/nuttx/nuttx.h:48: note: this is the location of the previous definition
48 | #define container_of(ptr, type, member) \
|
Signed-off-by: chao an <anchao@lixiang.com>
2024-02-29 10:19:49 +08:00
|
|
|
__t = list_container_of(__node, type, member); \
|
2022-10-03 22:00:20 +08:00
|
|
|
} \
|
|
|
|
|
__t; \
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
#define list_next_type(list, item, type, member) \
|
|
|
|
|
({ \
|
|
|
|
|
FAR struct list_node *__node = list_next(list, item); \
|
|
|
|
|
FAR type *__t = NULL; \
|
|
|
|
|
if(__node) \
|
|
|
|
|
{ \
|
nuttx/list: rename container_of to list_container_of from public header
Use private naming to avoid conflicts with user applications
In file included from libuv/src/unix/internal.h:25,
from libuv/src/unix/udp.c:23:
libuv/src/uv-common.h:57: warning: "container_of" redefined
57 | #define container_of(ptr, type, member) \
|
In file included from nuttx/include/nuttx/list.h:47,
from nuttx/include/nuttx/tls.h:40,
from nuttx/include/nuttx/sched.h:48,
from nuttx/include/nuttx/arch.h:87,
from nuttx/include/nuttx/userspace.h:35,
from nuttx/include/nuttx/mm/mm.h:30,
from nuttx/include/nuttx/kmalloc.h:34,
from nuttx/include/nuttx/lib/lib.h:31,
from nuttx/include/stdio.h:35,
from apps/system/libuv/libuv/include/uv.h:59,
from libuv/src/unix/udp.c:22:
nuttx/include/nuttx/nuttx.h:48: note: this is the location of the previous definition
48 | #define container_of(ptr, type, member) \
|
Signed-off-by: chao an <anchao@lixiang.com>
2024-02-29 10:19:49 +08:00
|
|
|
__t = list_container_of(__node, type, member); \
|
2022-10-03 22:00:20 +08:00
|
|
|
} \
|
|
|
|
|
__t; \
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
#define list_next_wrap_type(list, item, type, member) \
|
|
|
|
|
({ \
|
|
|
|
|
FAR struct list_node *__node = list_next_wrap(list, item); \
|
|
|
|
|
FAR type *__t = NULL; \
|
|
|
|
|
if(__node) \
|
|
|
|
|
{ \
|
nuttx/list: rename container_of to list_container_of from public header
Use private naming to avoid conflicts with user applications
In file included from libuv/src/unix/internal.h:25,
from libuv/src/unix/udp.c:23:
libuv/src/uv-common.h:57: warning: "container_of" redefined
57 | #define container_of(ptr, type, member) \
|
In file included from nuttx/include/nuttx/list.h:47,
from nuttx/include/nuttx/tls.h:40,
from nuttx/include/nuttx/sched.h:48,
from nuttx/include/nuttx/arch.h:87,
from nuttx/include/nuttx/userspace.h:35,
from nuttx/include/nuttx/mm/mm.h:30,
from nuttx/include/nuttx/kmalloc.h:34,
from nuttx/include/nuttx/lib/lib.h:31,
from nuttx/include/stdio.h:35,
from apps/system/libuv/libuv/include/uv.h:59,
from libuv/src/unix/udp.c:22:
nuttx/include/nuttx/nuttx.h:48: note: this is the location of the previous definition
48 | #define container_of(ptr, type, member) \
|
Signed-off-by: chao an <anchao@lixiang.com>
2024-02-29 10:19:49 +08:00
|
|
|
__t = list_container_of(__node, type, member); \
|
2022-10-03 22:00:20 +08:00
|
|
|
} \
|
|
|
|
|
__t; \
|
|
|
|
|
})
|
2019-01-27 11:56:25 -06:00
|
|
|
|
|
|
|
|
/* iterates over the list, node should be struct list_node* */
|
|
|
|
|
|
|
|
|
|
#define list_for_every(list, node) \
|
|
|
|
|
for(node = (list)->next; node != (list); node = node->next)
|
|
|
|
|
|
|
|
|
|
/* iterates over the list in a safe way for deletion of current node
|
|
|
|
|
* node and temp_node should be struct list_node*
|
|
|
|
|
*/
|
|
|
|
|
|
2022-10-03 22:00:20 +08:00
|
|
|
#define list_for_every_safe(list, node, temp) \
|
|
|
|
|
for(node = (list)->next, temp = node->next; \
|
|
|
|
|
node != (list); node = temp, temp = node->next)
|
2019-01-27 11:56:25 -06:00
|
|
|
|
|
|
|
|
/* iterates over the list, entry should be the container structure type */
|
|
|
|
|
|
|
|
|
|
#define list_for_every_entry(list, entry, type, member) \
|
nuttx/list: rename container_of to list_container_of from public header
Use private naming to avoid conflicts with user applications
In file included from libuv/src/unix/internal.h:25,
from libuv/src/unix/udp.c:23:
libuv/src/uv-common.h:57: warning: "container_of" redefined
57 | #define container_of(ptr, type, member) \
|
In file included from nuttx/include/nuttx/list.h:47,
from nuttx/include/nuttx/tls.h:40,
from nuttx/include/nuttx/sched.h:48,
from nuttx/include/nuttx/arch.h:87,
from nuttx/include/nuttx/userspace.h:35,
from nuttx/include/nuttx/mm/mm.h:30,
from nuttx/include/nuttx/kmalloc.h:34,
from nuttx/include/nuttx/lib/lib.h:31,
from nuttx/include/stdio.h:35,
from apps/system/libuv/libuv/include/uv.h:59,
from libuv/src/unix/udp.c:22:
nuttx/include/nuttx/nuttx.h:48: note: this is the location of the previous definition
48 | #define container_of(ptr, type, member) \
|
Signed-off-by: chao an <anchao@lixiang.com>
2024-02-29 10:19:49 +08:00
|
|
|
for(entry = list_container_of((list)->next, type, member); \
|
2022-10-03 22:00:20 +08:00
|
|
|
&entry->member != (list); \
|
nuttx/list: rename container_of to list_container_of from public header
Use private naming to avoid conflicts with user applications
In file included from libuv/src/unix/internal.h:25,
from libuv/src/unix/udp.c:23:
libuv/src/uv-common.h:57: warning: "container_of" redefined
57 | #define container_of(ptr, type, member) \
|
In file included from nuttx/include/nuttx/list.h:47,
from nuttx/include/nuttx/tls.h:40,
from nuttx/include/nuttx/sched.h:48,
from nuttx/include/nuttx/arch.h:87,
from nuttx/include/nuttx/userspace.h:35,
from nuttx/include/nuttx/mm/mm.h:30,
from nuttx/include/nuttx/kmalloc.h:34,
from nuttx/include/nuttx/lib/lib.h:31,
from nuttx/include/stdio.h:35,
from apps/system/libuv/libuv/include/uv.h:59,
from libuv/src/unix/udp.c:22:
nuttx/include/nuttx/nuttx.h:48: note: this is the location of the previous definition
48 | #define container_of(ptr, type, member) \
|
Signed-off-by: chao an <anchao@lixiang.com>
2024-02-29 10:19:49 +08:00
|
|
|
entry = list_container_of(entry->member.next, type, member))
|
2019-01-27 11:56:25 -06:00
|
|
|
|
|
|
|
|
/* iterates over the list in a safe way for deletion of current node
|
|
|
|
|
* entry and temp_entry should be the container structure type *
|
|
|
|
|
*/
|
|
|
|
|
|
2022-10-03 22:00:20 +08:00
|
|
|
#define list_for_every_entry_safe(list, entry, temp, type, member) \
|
nuttx/list: rename container_of to list_container_of from public header
Use private naming to avoid conflicts with user applications
In file included from libuv/src/unix/internal.h:25,
from libuv/src/unix/udp.c:23:
libuv/src/uv-common.h:57: warning: "container_of" redefined
57 | #define container_of(ptr, type, member) \
|
In file included from nuttx/include/nuttx/list.h:47,
from nuttx/include/nuttx/tls.h:40,
from nuttx/include/nuttx/sched.h:48,
from nuttx/include/nuttx/arch.h:87,
from nuttx/include/nuttx/userspace.h:35,
from nuttx/include/nuttx/mm/mm.h:30,
from nuttx/include/nuttx/kmalloc.h:34,
from nuttx/include/nuttx/lib/lib.h:31,
from nuttx/include/stdio.h:35,
from apps/system/libuv/libuv/include/uv.h:59,
from libuv/src/unix/udp.c:22:
nuttx/include/nuttx/nuttx.h:48: note: this is the location of the previous definition
48 | #define container_of(ptr, type, member) \
|
Signed-off-by: chao an <anchao@lixiang.com>
2024-02-29 10:19:49 +08:00
|
|
|
for(entry = list_container_of((list)->next, type, member), \
|
|
|
|
|
temp = list_container_of(entry->member.next, type, member); \
|
2022-10-03 22:00:20 +08:00
|
|
|
&entry->member != (list); entry = temp, \
|
nuttx/list: rename container_of to list_container_of from public header
Use private naming to avoid conflicts with user applications
In file included from libuv/src/unix/internal.h:25,
from libuv/src/unix/udp.c:23:
libuv/src/uv-common.h:57: warning: "container_of" redefined
57 | #define container_of(ptr, type, member) \
|
In file included from nuttx/include/nuttx/list.h:47,
from nuttx/include/nuttx/tls.h:40,
from nuttx/include/nuttx/sched.h:48,
from nuttx/include/nuttx/arch.h:87,
from nuttx/include/nuttx/userspace.h:35,
from nuttx/include/nuttx/mm/mm.h:30,
from nuttx/include/nuttx/kmalloc.h:34,
from nuttx/include/nuttx/lib/lib.h:31,
from nuttx/include/stdio.h:35,
from apps/system/libuv/libuv/include/uv.h:59,
from libuv/src/unix/udp.c:22:
nuttx/include/nuttx/nuttx.h:48: note: this is the location of the previous definition
48 | #define container_of(ptr, type, member) \
|
Signed-off-by: chao an <anchao@lixiang.com>
2024-02-29 10:19:49 +08:00
|
|
|
temp = list_container_of(temp->member.next, type, member))
|
2019-01-27 11:56:25 -06:00
|
|
|
|
2023-11-01 19:47:01 +08:00
|
|
|
/* Iterate from a given entry node in a safe way */
|
|
|
|
|
|
|
|
|
|
#define list_for_every_entry_safe_from(list, cur, temp, type, member) \
|
|
|
|
|
for ((temp) = list_next_entry(cur, type, member); \
|
|
|
|
|
&(cur)->member != (list); \
|
|
|
|
|
(cur) = (temp), (temp) = list_next_entry(temp, type, member))
|
|
|
|
|
|
2023-08-11 18:28:10 +08:00
|
|
|
#define list_for_every_entry_continue(list, head, type, member) \
|
|
|
|
|
for ((list) = list_next_entry(list, type, member); \
|
|
|
|
|
&(list)->member != (head); \
|
|
|
|
|
(list) = list_next_entry(list, type, member))
|
|
|
|
|
|
2023-07-15 16:37:22 +08:00
|
|
|
/* iterates over the list in reverse order, entry should be the container
|
|
|
|
|
* structure type
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#define list_for_every_entry_reverse(list, entry, type, member) \
|
nuttx/list: rename container_of to list_container_of from public header
Use private naming to avoid conflicts with user applications
In file included from libuv/src/unix/internal.h:25,
from libuv/src/unix/udp.c:23:
libuv/src/uv-common.h:57: warning: "container_of" redefined
57 | #define container_of(ptr, type, member) \
|
In file included from nuttx/include/nuttx/list.h:47,
from nuttx/include/nuttx/tls.h:40,
from nuttx/include/nuttx/sched.h:48,
from nuttx/include/nuttx/arch.h:87,
from nuttx/include/nuttx/userspace.h:35,
from nuttx/include/nuttx/mm/mm.h:30,
from nuttx/include/nuttx/kmalloc.h:34,
from nuttx/include/nuttx/lib/lib.h:31,
from nuttx/include/stdio.h:35,
from apps/system/libuv/libuv/include/uv.h:59,
from libuv/src/unix/udp.c:22:
nuttx/include/nuttx/nuttx.h:48: note: this is the location of the previous definition
48 | #define container_of(ptr, type, member) \
|
Signed-off-by: chao an <anchao@lixiang.com>
2024-02-29 10:19:49 +08:00
|
|
|
for(entry = list_container_of((list)->prev, type, member); \
|
2023-07-15 16:37:22 +08:00
|
|
|
&entry->member != (list); \
|
nuttx/list: rename container_of to list_container_of from public header
Use private naming to avoid conflicts with user applications
In file included from libuv/src/unix/internal.h:25,
from libuv/src/unix/udp.c:23:
libuv/src/uv-common.h:57: warning: "container_of" redefined
57 | #define container_of(ptr, type, member) \
|
In file included from nuttx/include/nuttx/list.h:47,
from nuttx/include/nuttx/tls.h:40,
from nuttx/include/nuttx/sched.h:48,
from nuttx/include/nuttx/arch.h:87,
from nuttx/include/nuttx/userspace.h:35,
from nuttx/include/nuttx/mm/mm.h:30,
from nuttx/include/nuttx/kmalloc.h:34,
from nuttx/include/nuttx/lib/lib.h:31,
from nuttx/include/stdio.h:35,
from apps/system/libuv/libuv/include/uv.h:59,
from libuv/src/unix/udp.c:22:
nuttx/include/nuttx/nuttx.h:48: note: this is the location of the previous definition
48 | #define container_of(ptr, type, member) \
|
Signed-off-by: chao an <anchao@lixiang.com>
2024-02-29 10:19:49 +08:00
|
|
|
entry = list_container_of(entry->member.prev, type, member))
|
2023-07-15 16:37:22 +08:00
|
|
|
|
2019-01-27 11:56:25 -06:00
|
|
|
/****************************************************************************
|
|
|
|
|
* Public Type Definitions
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
struct list_node
|
|
|
|
|
{
|
|
|
|
|
FAR struct list_node *prev;
|
|
|
|
|
FAR struct list_node *next;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Inline Functions
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2020-08-23 01:15:21 +08:00
|
|
|
static inline FAR struct list_node *
|
|
|
|
|
list_remove_head(FAR struct list_node *list)
|
2019-01-27 11:56:25 -06:00
|
|
|
{
|
|
|
|
|
if (list->next != list)
|
|
|
|
|
{
|
|
|
|
|
FAR struct list_node *item = list->next;
|
|
|
|
|
list_delete(item);
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-23 01:15:21 +08:00
|
|
|
static inline FAR struct list_node *
|
|
|
|
|
list_remove_tail(FAR struct list_node *list)
|
2019-01-27 11:56:25 -06:00
|
|
|
{
|
|
|
|
|
if (list->prev != list)
|
|
|
|
|
{
|
|
|
|
|
FAR struct list_node *item = list->prev;
|
|
|
|
|
list_delete(item);
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline size_t list_length(FAR struct list_node *list)
|
|
|
|
|
{
|
|
|
|
|
FAR struct list_node *node = list;
|
|
|
|
|
size_t cnt = 0;
|
|
|
|
|
|
|
|
|
|
list_for_every(list, node)
|
|
|
|
|
{
|
|
|
|
|
cnt++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return cnt;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-23 01:15:21 +08:00
|
|
|
#endif /* __INCLUDE_NUTTX_LIST_H */
|