sdlbomber/src/list.h

61 lines
2.2 KiB
C
Raw Normal View History

#ifndef LIST_H
#define LIST_H
2021-09-15 16:52:43 +00:00
/* from linux kernel (with some changes for "iso" c) */
2009-08-11 17:09:59 +00:00
2021-09-15 16:52:43 +00:00
#define container_of(ptr, type, member) \
((type *)( (char *)(__typeof__( ((type *)0)->member ) *)(ptr) - offsetof(type,member)))
2009-08-11 15:19:43 +00:00
/**
* 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_struct within the struct.
*/
#define list_entry(ptr, type, member) container_of(ptr, type, member)
2009-08-11 15:19:43 +00:00
2009-08-19 11:16:28 +00:00
void alloc_things(void);
void *_allocentry(size_t size);
#define allocentry(type) (type*) _allocentry(sizeof(type))
void freeentry(void *ptr);
2009-08-11 15:19:43 +00:00
void list_add_tail(listhead *header, listhead *entry);
#define addtail(head, entry) list_add_tail(head, &(entry->list));
2009-08-11 15:46:32 +00:00
/* remove entry from list */
void list_del(listhead *entry);
#define removeitem(entry) list_del(&(entry->list));
void list_init_head(listhead *head);
2009-08-19 11:16:28 +00:00
void things_list_clear(listhead *head); /* listhead member must be the first member */
/**
* list_for_each_entry - iterate over list of given type
* @pos: the type * to use as a loop cursor.
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
*/
#define list_for_each_entry(pos, head, member) \
2021-09-15 16:52:43 +00:00
for (pos = list_entry((head)->next, __typeof__(*pos), member); \
/* prefetch(pos->member.next), */ \
&pos->member != (head); \
2021-09-15 16:52:43 +00:00
pos = list_entry(pos->member.next, __typeof__(*pos), member))
/**
* list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
* @pos:<-->the type * to use as a loop cursor.
* @n:<><-->another type * to use as temporary storage
* @head:<->the head for your list.
* @member:>the name of the list_struct within the struct.
*/
#define list_for_each_entry_safe(pos, n, head, member) \
2021-09-15 16:52:43 +00:00
for (pos = list_entry((head)->next, __typeof__(*pos), member), \
n = list_entry(pos->member.next, __typeof__(*pos), member); \
&pos->member != (head); \
2021-09-15 16:52:43 +00:00
pos = n, n = list_entry(n->member.next, __typeof__(*n), member))
2009-08-11 15:46:32 +00:00
2009-08-11 17:09:59 +00:00
#define list_empty(head) ((head) == (head)->next)
#endif