Contiki-NG
|
Macros | |
#define | LIST(name) |
Declare a linked list. | |
#define | LIST_STRUCT(name) |
Declare a linked list inside a structure declaraction. | |
#define | LIST_STRUCT_INIT(struct_ptr, name) |
Initialize a linked list that is part of a structure. | |
Typedefs | |
typedef void ** | list_t |
The linked list type. | |
typedef void *const * | const_list_t |
The non-modifiable linked list type. | |
Functions | |
void * | list_tail (const_list_t list) |
Get the tail of a list. | |
void | list_add (list_t list, void *item) |
Add an item at the end of a list. | |
void | list_push (list_t list, void *item) |
Add an item to the start of the list. | |
void * | list_chop (list_t list) |
Remove the last object on the list. | |
void * | list_pop (list_t list) |
Remove the first object on a list. | |
void | list_remove (list_t list, const void *item) |
Remove a specific element from a list. | |
int | list_length (const_list_t list) |
Get the length of a list. | |
void | list_insert (list_t list, void *previtem, void *newitem) |
Insert an item after a specified item on the list. | |
bool | list_contains (const_list_t list, const void *item) |
Check if the list contains an item. | |
static void | list_init (list_t list) |
Initialize a list. | |
static void * | list_head (const_list_t list) |
Get a pointer to the first element of a list. | |
static void | list_copy (list_t dest, const_list_t src) |
Duplicate a list. | |
static void * | list_item_next (const void *item) |
Get the next item following this item. | |
The linked list library provides a set of functions for manipulating linked lists.
A linked list is made up of elements where the first element must be a pointer. This pointer is used by the linked list library to form lists of the elements.
Lists are declared with the LIST() macro. The declaration specifies the name of the list that later is used with all list functions.
Lists can be manipulated by inserting or removing elements from either sides of the list (list_push(), list_add(), list_pop(), list_chop()). A specified element can also be removed from inside a list with list_remove(). The head and tail of a list can be extracted using list_head() and list_tail(), respectively.
This library is not safe to be used within an interrupt context.
#define LIST | ( | name | ) |
Declare a linked list.
This macro declares a linked list with the specified type
. The type must be a structure (struct
) with its first element being a pointer. This pointer is used by the linked list library to form the linked lists.
The list variable is declared as static to make it easy to use in a single C module without unnecessarily exporting the name to other modules.
name | The name of the list. |
#define LIST_STRUCT | ( | name | ) |
Declare a linked list inside a structure declaraction.
This macro declares a linked list with the specified type
. The type must be a structure (struct
) with its first element being a pointer. This pointer is used by the linked list library to form the linked lists.
Internally, the list is defined as two items: the list itself and a pointer to the list. The pointer has the name of the parameter to the macro and the name of the list is a concatenation of the name and the suffix "_list". The pointer must point to the list for the list to work. Thus the list must be initialized before using.
The list is initialized with the LIST_STRUCT_INIT() macro.
name | The name of the list. |
#define LIST_STRUCT_INIT | ( | struct_ptr, | |
name ) |
Initialize a linked list that is part of a structure.
This macro sets up the internal pointers in a list that has been defined as part of a struct. This macro must be called before using the list.
struct_ptr | A pointer to the struct |
name | The name of the list. |
Definition at line 126 of file list.h.
Referenced by accept(), tsch_schedule_add_slotframe(), uip_ds6_nbr_add(), and uip_ds6_nbr_update_ll().
void list_add | ( | list_t | list, |
void * | item ) |
Add an item at the end of a list.
This function adds an item to the end of the list.
list | The list. |
item | A pointer to the item to be added. |
Definition at line 71 of file list.c.
References list_remove(), and list_tail().
Referenced by aux_ctrl_register_consumer(), coap_activate_resource(), ctimer_reset(), ctimer_restart(), ctimer_set_with_process(), gpio_hal_register_handler(), lpm_register_module(), mqtt_register(), queue_enqueue(), shell_commands_init(), sixp_trans_alloc(), snmp_mib_add(), tsch_schedule_add_link(), tsch_schedule_add_slotframe(), uip_icmp6_echo_reply_callback_add(), uip_icmp6_register_input_handler(), uip_mcast6_route_add(), uip_nameserver_update(), and uip_sr_update_node().
void * list_chop | ( | list_t | list | ) |
bool list_contains | ( | const_list_t | list, |
const void * | item ) |
Check if the list contains an item.
list | The list that is checked |
item | An item to look for in the list |
This function searches for an item in the list and returns 0 if the list does not contain the item, and 1 if the item is present in the list.
|
inlinestatic |
Duplicate a list.
This function duplicates a list by copying the list reference, but not the elements.
dest | The destination list. |
src | The source list. |
|
inlinestatic |
Get a pointer to the first element of a list.
This function returns a pointer to the first element of the list. The element will not be removed from the list.
list | The list. |
Definition at line 169 of file list.h.
Referenced by accept(), aux_ctrl_power_down(), aux_ctrl_power_up(), coap_get_first_resource(), coap_timer_run(), coap_timer_time_to_next_expiration(), ctimer_expired(), icmp_in(), lpm_shutdown(), queue_peek(), sixp_trans_find(), sixp_trans_init(), snmp_mib_add(), snmp_mib_find(), snmp_mib_find_next(), stack_peek(), tsch_schedule_get_link_by_handle(), tsch_schedule_get_link_by_offsets(), tsch_schedule_get_link_by_timeslot(), tsch_schedule_get_next_active_link(), tsch_schedule_get_slotframe_by_handle(), tsch_schedule_print(), tsch_schedule_remove_all_slotframes(), tsch_schedule_remove_link_by_offsets(), tsch_schedule_remove_slotframe(), tsch_schedule_slotframe_head(), uip_ds6_link_callback(), uip_ds6_nbr_head(), uip_ds6_nbr_ll_lookup(), uip_ds6_nbr_next(), uip_mcast6_route_list_head(), uip_mcast6_route_lookup(), uip_mcast6_route_rm(), uip_nameserver_get(), uip_nameserver_next_expiration(), uip_nameserver_update(), uip_sr_free_all(), uip_sr_get_node(), uip_sr_node_head(), and uip_sr_periodic().
|
inlinestatic |
Initialize a list.
This function initalizes a list. The list will be empty after this function has been called.
list | The list to be initialized. |
Definition at line 152 of file list.h.
Referenced by coap_timer_init(), ctimer_init(), gpio_hal_init(), lpm_init(), queue_init(), shell_commands_init(), sixp_trans_init(), snmp_mib_init(), stack_init(), tsch_schedule_init(), uip_mcast6_route_init(), and uip_sr_init().
void list_insert | ( | list_t | list, |
void * | previtem, | ||
void * | newitem ) |
Insert an item after a specified item on the list.
list | The list |
previtem | The item after which the new item should be inserted |
newitem | The new item that is to be inserted |
Definition at line 173 of file list.c.
References list_push(), and list_remove().
Referenced by accept(), and snmp_mib_add().
|
inlinestatic |
Get the next item following this item.
item | A list item |
This function takes a list item and returns the next item on the list, or NULL if there are no more items on the list. This function is used when iterating through lists.
Definition at line 294 of file list.h.
Referenced by accept(), buffer_reclaim(), coap_get_next_resource(), icmp_in(), tsch_schedule_get_link_by_handle(), tsch_schedule_get_link_by_offsets(), tsch_schedule_get_link_by_timeslot(), tsch_schedule_get_next_active_link(), tsch_schedule_get_slotframe_by_handle(), tsch_schedule_print(), tsch_schedule_remove_link_by_offsets(), tsch_schedule_slotframe_next(), uip_ds6_link_callback(), uip_ds6_nbr_next(), uip_mcast6_route_lookup(), uip_mcast6_route_rm(), uip_nameserver_get(), uip_nameserver_next_expiration(), uip_nameserver_update(), uip_sr_free_all(), uip_sr_get_node(), uip_sr_node_next(), and uip_sr_periodic().
int list_length | ( | const_list_t | list | ) |
Get the length of a list.
This function counts the number of elements on a specified list.
list | The list. |
Definition at line 160 of file list.c.
Referenced by uip_ds6_nbr_add(), uip_ds6_nbr_num(), uip_ds6_nbr_update_ll(), uip_mcast6_route_count(), uip_nameserver_count(), and uip_nameserver_next_expiration().
void * list_pop | ( | list_t | list | ) |
Remove the first object on a list.
This function removes the first object on the list and returns a pointer to it.
list | The list. |
Definition at line 122 of file list.c.
Referenced by buffer_reclaim(), queue_dequeue(), and stack_pop().
void list_remove | ( | list_t | list, |
const void * | item ) |
Remove a specific element from a list.
This function removes a specified element from the list.
list | The list. |
item | The item that is to be removed from the list. |
Definition at line 134 of file list.c.
Referenced by aux_ctrl_unregister_consumer(), coap_timer_run(), coap_timer_stop(), ctimer_stop(), list_add(), list_insert(), list_push(), lpm_unregister_module(), sixp_trans_free(), tsch_schedule_remove_link(), tsch_schedule_remove_slotframe(), uip_icmp6_echo_reply_callback_rm(), uip_mcast6_route_rm(), uip_nameserver_update(), uip_sr_free_all(), and uip_sr_periodic().
void * list_tail | ( | const_list_t | list | ) |
Get the tail of a list.
This function returns a pointer to the elements following the first element of a list. No elements are removed by this function.
list | The list |
Definition at line 57 of file list.c.
Referenced by list_add().