X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/620a2ee90a60979955c318cc1b37741184137bd6..7c7b5f05d39b7739d990f71256a2267ec67a6913:/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 5afc36a..ecce44a 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 { @@ -41,13 +41,19 @@ llist_init_head(struct llist_header* head) static inline void llist_append(struct llist_header* head, struct llist_header* elem) { - __llist_add(elem, head, head->next); + __llist_add(elem, head->prev, head); } static inline void llist_prepend(struct llist_header* head, struct llist_header* elem) { - __llist_add(elem, head->prev, head); + __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 @@ -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. @@ -87,4 +99,29 @@ llist_empty(struct llist_header* elem) &pos->member != (head); \ pos = n, n = list_entry(n->member.next, typeof(*n), member)) +struct hlist_node +{ + struct hlist_node *next, **pprev; +}; + +static inline void +hlist_delete(struct hlist_node* node) +{ + if (!node->pprev) + return; + *node->pprev = node->next; + node->next = 0; + node->pprev = 0; +} + +static inline void +hlist_add(struct hlist_node** head, struct hlist_node* node) +{ + node->next = *head; + if (*head) { + (*head)->pprev = &node->next; + } + node->pprev = head; + *head = node; +} #endif /* __LUNAIX_LLIST_H */