Since we're going to be using lists for keeping track of spinners add some generic list helpers from the kernel. Signed-off-by: Abdiel Janulgue <abdiel.janulgue@xxxxxxxxxxxxxxx> --- lib/igt_aux.c | 39 +++++++++++++++++++++++++++++++++++++++ lib/igt_aux.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/lib/igt_aux.c b/lib/igt_aux.c index b5ae854..28af1d4 100644 --- a/lib/igt_aux.c +++ b/lib/igt_aux.c @@ -1265,3 +1265,42 @@ double igt_stop_siglatency(struct igt_mean *result) return mean; } + +static void __list_add(struct list_head *new, + struct list_head *prev, + struct list_head *next) +{ + next->prev = new; + new->next = next; + new->prev = prev; + prev->next = new; +} + +static void __list_del(struct list_head * prev, struct list_head * next) +{ + next->prev = prev; + prev->next = next; +} + +void INIT_LIST_HEAD(struct list_head *list) +{ + list->next = list; + list->prev = list; +} + +void list_add(struct list_head *new, struct list_head *head) +{ + __list_add(new, head, head->next); +} + +void list_del(struct list_head *entry) +{ + __list_del(entry->prev, entry->next); + entry->next = NULL; + entry->prev = NULL; +} + +bool list_empty(const struct list_head *head) +{ + return head->next == head; +} diff --git a/lib/igt_aux.h b/lib/igt_aux.h index d4da499..73836d0 100644 --- a/lib/igt_aux.h +++ b/lib/igt_aux.h @@ -274,4 +274,50 @@ double igt_stop_siglatency(struct igt_mean *result); void igt_set_module_param(const char *name, const char *val); void igt_set_module_param_int(const char *name, int val); +/* + * This list data structure is a derived from the Linux kerne's list.h + */ + +struct list_head { + struct list_head *next, *prev; +}; + +#define LIST_HEAD_INIT(name) { &(name), &(name) } + +#define LIST_HEAD(name) \ + struct list_head name = LIST_HEAD_INIT(name) + +void INIT_LIST_HEAD(struct list_head *list); + +void list_add(struct list_head *new, struct list_head *head); + +void list_del(struct list_head *entry); + +bool list_empty(const struct list_head *head); + +#undef offsetof +#ifdef __compiler_offsetof +#define offsetof(TYPE, MEMBER) __compiler_offsetof(TYPE, MEMBER) +#else +#define offsetof(TYPE, MEMBER) ((size_t)&((TYPE *)0)->MEMBER) +#endif + +#define container_of(ptr, type, member) ({ \ + const typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );}) + +#define list_entry(ptr, type, member) \ + container_of(ptr, type, member) + +#define list_next_entry(pos, member) \ + list_entry((pos)->member.next, typeof(*(pos)), member) + +#define list_first_entry(ptr, type, member) \ + list_entry((ptr)->next, type, member) + +#define list_for_each_entry(pos, head, member) \ + for (pos = list_first_entry(head, typeof(*pos), member); \ + &pos->member != (head); \ + pos = list_next_entry(pos, member)) + #endif /* IGT_AUX_H */ -- 2.7.4 _______________________________________________ Intel-gfx mailing list Intel-gfx@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/intel-gfx