|
|
|
@ -2,15 +2,32 @@
|
|
|
|
|
|
|
|
|
|
#include <gay/clist.h>
|
|
|
|
|
#include <gay/config.h>
|
|
|
|
|
#include <gay/kprintf.h>
|
|
|
|
|
|
|
|
|
|
void clist_init(struct clist *head)
|
|
|
|
|
{
|
|
|
|
|
# if CFG_DEBUG_CLIST
|
|
|
|
|
if (head->next == head && head->prev == head)
|
|
|
|
|
kprintf("clist_init(%p) called multiple times\n", head);
|
|
|
|
|
# endif
|
|
|
|
|
|
|
|
|
|
head->next = head;
|
|
|
|
|
head->prev = head;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void clist_add(struct clist *head, struct clist *new)
|
|
|
|
|
{
|
|
|
|
|
# if CFG_DEBUG_CLIST
|
|
|
|
|
if (sus_nil(head->next) || sus_nil(head->prev)) {
|
|
|
|
|
kprintf("clist_add(%p, %p): head seems uninitialized\n", head, new);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (sus_nil(new)) {
|
|
|
|
|
kprintf("clist_add(%p, %p): new node is NULL!\n", head, new);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
# endif
|
|
|
|
|
|
|
|
|
|
head->prev->next = new;
|
|
|
|
|
new->next = head;
|
|
|
|
|
|
|
|
|
@ -32,10 +49,38 @@ void clist_del(struct clist *node)
|
|
|
|
|
node->next->prev = node->prev;
|
|
|
|
|
node->prev->next = node->next;
|
|
|
|
|
|
|
|
|
|
# ifdef DEBUG
|
|
|
|
|
node->next = NULL;
|
|
|
|
|
node->prev = NULL;
|
|
|
|
|
# if CFG_DEBUG_CLIST
|
|
|
|
|
node->next = nil;
|
|
|
|
|
node->prev = nil;
|
|
|
|
|
# endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct clist *clist_del_first(struct clist *head)
|
|
|
|
|
{
|
|
|
|
|
# if CFG_DEBUG_CLIST
|
|
|
|
|
if (clist_is_empty(head)) {
|
|
|
|
|
kprintf("clist_del_first(%p): empty list!\n", head);
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
# endif
|
|
|
|
|
|
|
|
|
|
struct clist *first = head->next;
|
|
|
|
|
clist_del(first);
|
|
|
|
|
return first;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct clist *clist_del_last(struct clist *head)
|
|
|
|
|
{
|
|
|
|
|
# ifdef CFG_DEBUG_CLIST
|
|
|
|
|
if (clist_is_empty(head)) {
|
|
|
|
|
kprintf("clist_del_last(%p): empty list!\n", head);
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
# endif
|
|
|
|
|
|
|
|
|
|
struct clist *last = head->prev;
|
|
|
|
|
clist_del(last);
|
|
|
|
|
return last;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|