X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/af8e873ae38b72a56a89485c62bb5ccd22a9f8a7..b60166b327a9108b07e3069fa6568a451529ffd9:/lunaix-os/includes/lunaix/ds/llist.h diff --git a/lunaix-os/includes/lunaix/ds/llist.h b/lunaix-os/includes/lunaix/ds/llist.h index 6129ca0..1eec54b 100644 --- a/lunaix-os/includes/lunaix/ds/llist.h +++ b/lunaix-os/includes/lunaix/ds/llist.h @@ -12,7 +12,7 @@ #ifndef __LUNAIX_LLIST_H #define __LUNAIX_LLIST_H -#include +#include struct llist_header { @@ -50,6 +50,12 @@ llist_prepend(struct llist_header* head, struct llist_header* elem) __llist_add(elem, head, head->next); } +static inline void +llist_insert_after(struct llist_header* head, struct llist_header* elem) +{ + __llist_add(elem, head, head->next); +} + static inline void llist_delete(struct llist_header* elem) { @@ -67,6 +73,12 @@ llist_empty(struct llist_header* elem) return elem->next == elem && elem->prev == elem; } +#define DEFINE_LLIST(name) \ + struct llist_header name = (struct llist_header) \ + { \ + .prev = &name, .next = &name \ + } + /** * list_entry - get the struct for this entry * @ptr: the &struct list_head pointer. @@ -75,6 +87,22 @@ llist_empty(struct llist_header* elem) */ #define list_entry(ptr, type, member) container_of(ptr, type, member) +/** + * list_next - get the struct for next 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_next(current, type, member) container_of(current->member.next, type, member) + +/** + * list_prev - get the struct for prev 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_prev(current, type, member) container_of(current->member.prev, type, member) + /** * list_for_each_entry - iterate over list of given type * @pos: the type * to use as a loop counter. @@ -93,8 +121,10 @@ struct hlist_node }; static inline void -hlist_del(struct hlist_node* node) +hlist_delete(struct hlist_node* node) { + if (!node->pprev) + return; *node->pprev = node->next; node->next = 0; node->pprev = 0;