Skip to content

Commit

Permalink
list: update list.h
Browse files Browse the repository at this point in the history
The function name comes from list.h inside Linux,
but rewrite from scratch to avoid the copyright issue.
Since many developers are familiar with Linux list API.

Signed-off-by: ligd <[email protected]>
  • Loading branch information
GUIDINGLI authored and xiaoxiang781216 committed Sep 25, 2023
1 parent 50cad15 commit dc096f9
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions include/nuttx/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
#define list_entry(ptr, type, member) container_of(ptr, type, member)
#define list_first_entry(list, type, member) container_of((list)->next, type, member)
#define list_last_entry(list, type, member) container_of((list)->prev, type, member)
#define list_next_entry(list, type, member) container_of((list)->member.next, type, member)
#define list_prev_entry(list, type, member) container_of((list)->member.prev, type, member)

#define list_add_after(entry, new_entry) list_add_head(entry, new_entry)
#define list_add_head(list, item) \
Expand Down Expand Up @@ -129,6 +131,14 @@
} \
while (0)

#define list_delete_init(item) \
do \
{ \
list_delete(item); \
list_initialize(item); \
} \
while (0)

#define list_remove_head_type(list, type, member) \
({ \
FAR struct list_node *__node = list_remove_head(list); \
Expand Down Expand Up @@ -247,6 +257,11 @@
&entry->member != (list); entry = temp, \
temp = container_of(temp->member.next, type, member))

#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))

/* iterates over the list in reverse order, entry should be the container
* structure type
*/
Expand Down

0 comments on commit dc096f9

Please sign in to comment.