Top |
void | IGT_INIT_LIST_HEAD () |
void | igt_list_add () |
void | igt_list_del () |
void | igt_list_del_init () |
void | igt_list_move () |
void | igt_list_move_tail () |
int | igt_list_length () |
bool | igt_list_empty () |
#define | igt_container_of() |
#define | igt_list_for_each_entry() |
#define | igt_list_for_each_entry_safe() |
#define | igt_list_for_each_entry_reverse() |
#define | igt_list_for_each_entry_safe_reverse() |
#define | IGT_LIST_HEAD() |
#define | igt_list_add_tail() |
#define | igt_list_first_entry() |
#define | igt_list_last_entry() |
This list data structure mimics the one we can find in the kernel. A few bonus helpers are provided.
igt_list is a doubly-linked list where an instance of igt_list_head is a head sentinel and has to be initialized.
Example usage:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
struct igt_list_head foo_head; struct element { int foo; struct igt_list_head link; }; struct element e1, e2, e3; IGT_INIT_LIST_HEAD(&foo_head); igt_list_add(&e1.link, &foo_head); // e1 is the first element igt_list_add(&e2.link, &foo_head); // e2 is now the first element igt_list_add(&e3.link, &e2.link); // insert e3 after e2 printf("list length: %d\n", igt_list_length(&foo_head)); struct element *iter; igt_list_for_each_entry(iter, &foo_head, link) { printf(" %d\n", iter->foo); } |
void igt_list_move_tail (struct igt_list_head *elem
,struct igt_list_head *list
);
#define igt_list_for_each_entry_safe_reverse(pos, tmp, head, member)
#define IGT_LIST_HEAD(name) struct igt_list_head name = { &(name), &(name) }
Instead of having to use
list can be defined using
this helper, e.g. IGT_INIT_LIST_HEAD()
static IGT_LIST_HEAD(list);