1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#ifndef __CIRCULARLIST__
#define __CIRCULARLIST__
/**
* ciruclar double linked list implementation
*
**/
#include "util.h"
#include<stdio.h>
struct circular_list {
struct circular_list *next;
struct circular_list *prev;
};
#define CIRCULARLIST_INIT(name) do { (name)->next = (name); (name)->prev = (name); } while(0);
static int inline __circular_list_insert(struct circular_list *prev, struct circular_list *new, struct circular_list *next)
{
prev->next = new;
new->prev = prev;
new->next = next;
next->prev = new;
}
static int inline circular_list_insert_after(struct circular_list *list, struct circular_list *new_elem)
{
return __circular_list_insert(list, new_elem, list->next);
}
static int inline circular_list_insert_before(struct circular_list *list, struct circular_list *new_elem)
{
return __circular_list_insert(list->prev, new_elem, list);
}
static void inline __circular_list_delete(struct circular_list *prev, struct circular_list *elem, struct circular_list *next)
{
prev->next = next;
next->prev = prev;
elem->next = elem;
elem->prev = elem;
}
static void inline circular_list_delete(struct circular_list *elem)
{
__circular_list_delete(elem->prev, elem, elem->next);
}
#define circular_list_get_prev(elem) (elem)->prev
#define circular_list_get_next(elem) (elem)->next
#define CIRCULARLIST_FOR_EACH(pos, head) for(pos = head->next; pos != head; pos = pos->next)
#define CONTAINER_OF(ptr, type, member) ((type *)((char *)(ptr) - (unsigned long)(&((type *)0)->member)))
#endif
|