include/nuttx/list.h: support list entry macro
Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
This commit is contained in:
parent
d252b0b430
commit
c947ddd441
@ -40,6 +40,37 @@
|
|||||||
#define list_add_after(entry, new_entry) list_add_head(entry, new_entry)
|
#define list_add_after(entry, new_entry) list_add_head(entry, new_entry)
|
||||||
#define list_add_before(entry, new_entry) list_add_tail(entry, new_entry)
|
#define list_add_before(entry, new_entry) list_add_tail(entry, new_entry)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* list_entry - get the struct for this entry
|
||||||
|
* @ptr: the &struct list_head pointer.
|
||||||
|
* @type: the type of the struct this is embedded in.
|
||||||
|
* @member: the name of the list_head within the struct.
|
||||||
|
*/
|
||||||
|
#define list_entry(ptr, type, member) \
|
||||||
|
container_of(ptr, type, member)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* list_first_entry - get the first element from a list
|
||||||
|
* @ptr: the list head to take the element from.
|
||||||
|
* @type: the type of the struct this is embedded in.
|
||||||
|
* @member: the name of the list_head within the struct.
|
||||||
|
*
|
||||||
|
* Note, that list is expected to be not empty.
|
||||||
|
*/
|
||||||
|
#define list_first_entry(ptr, type, member) \
|
||||||
|
list_entry((ptr)->next, type, member)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* list_last_entry - get the last element from a list
|
||||||
|
* @ptr: the list head to take the element from.
|
||||||
|
* @type: the type of the struct this is embedded in.
|
||||||
|
* @member: the name of the list_head within the struct.
|
||||||
|
*
|
||||||
|
* Note, that list is expected to be not empty.
|
||||||
|
*/
|
||||||
|
#define list_last_entry(ptr, type, member) \
|
||||||
|
list_entry((ptr)->prev, type, member)
|
||||||
|
|
||||||
#define list_remove_head_type(list, type, element) (\
|
#define list_remove_head_type(list, type, element) (\
|
||||||
{\
|
{\
|
||||||
FAR struct list_node *__nod = list_remove_head(list);\
|
FAR struct list_node *__nod = list_remove_head(list);\
|
||||||
|
Loading…
Reference in New Issue
Block a user