OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [include/] [l4/] [lib/] [list.h] - Blame information for rev 6

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
#ifndef __LIST_H__
2
#define __LIST_H__
3
 
4
#include <l4/macros.h>
5
 
6
#define L4_DEADWORD                             0xDEADCCCC
7
 
8
struct link {
9
        struct link *next;
10
        struct link *prev;
11
};
12
 
13
static inline void link_init(struct link *l)
14
{
15
        l->next = l;
16
        l->prev = l;
17
}
18
 
19
#define LINK_INIT(link) { &(link), &(link) }
20
#define LINK_DECLARE(l) \
21
        struct link l = LINK_INIT(l)
22
 
23
static inline void list_insert(struct link *new, struct link *list)
24
{
25
        struct link *next = list->next;
26
 
27
        /*
28
         * The new link goes between the
29
         * current and next links on the list e.g.
30
         * list -> new -> next
31
         */
32
        new->next = next;
33
        next->prev = new;
34
        list->next = new;
35
        new->prev = list;
36
 
37
}
38
 
39
static inline void list_insert_tail(struct link *new, struct link *list)
40
{
41
        struct link *prev = list->prev;
42
 
43
        /*
44
         * The new link goes between the
45
         * current and prev links  on the list, e.g.
46
         * prev -> new -> list
47
         */
48
        new->next = list;
49
        list->prev = new;
50
        new->prev = prev;
51
        prev->next = new;
52
}
53
 
54
static inline void list_remove(struct link *link)
55
{
56
        struct link *prev = link->prev;
57
        struct link *next = link->next;
58
 
59
        prev->next = next;
60
        next->prev = prev;
61
 
62
        link->next = (struct link *)L4_DEADWORD;
63
        link->prev = (struct link *)L4_DEADWORD;
64
}
65
 
66
static inline void list_remove_init(struct link *link)
67
{
68
        struct link *prev = link->prev;
69
        struct link *next = link->next;
70
 
71
        //BUG_ON(prev == NULL || next == NULL || link == NULL);
72
        prev->next = next;
73
        next->prev = prev;
74
 
75
        link->next = link;
76
        link->prev = link;
77
}
78
 
79
/* Cuts the whole list from head and returns it */
80
static inline struct link *list_detach(struct link *head)
81
{
82
        struct link *next = head->next;
83
 
84
        /* Detach head from rest of the list */
85
        list_remove_init(head);
86
 
87
        /* Return detached list */
88
        return next;
89
}
90
 
91
/* append new_list to list given by head/end pair */
92
static inline void list_attach(struct link *new_list, struct link *head, struct link *end)
93
{
94
        /* attach new list at the end of original list */
95
        end->next = new_list;
96
        new_list->prev = end;
97
 
98
        /* go to the end of list to be attached */
99
        while (new_list->next != end->next)
100
                new_list = new_list->next;
101
 
102
        /* set end nodes properly */
103
        new_list->next = head;
104
        head->prev = new_list;
105
 
106
        /* set end to new end */
107
        end = new_list;
108
}
109
 
110
 
111
static inline int list_empty(struct link *list)
112
{
113
        return list->prev == list && list->next == list;
114
}
115
 
116
 
117
#define link_to_struct(link, struct_type, link_field)                                           \
118
        container_of(link, struct_type, link_field)
119
 
120
#define list_foreach_struct(struct_ptr, link_start, link_field)                                 \
121
        for (struct_ptr = link_to_struct((link_start)->next, typeof(*struct_ptr), link_field);  \
122
             &struct_ptr->link_field != (link_start);                                           \
123
             struct_ptr = link_to_struct(struct_ptr->link_field.next, typeof(*struct_ptr), link_field))
124
 
125
#define list_foreach_removable_struct(struct_ptr, temp_ptr, link_start, link_field)                     \
126
        for (struct_ptr = link_to_struct((link_start)->next, typeof(*struct_ptr), link_field),  \
127
             temp_ptr = link_to_struct((struct_ptr)->link_field.next, typeof(*struct_ptr), link_field);\
128
             &struct_ptr->link_field != (link_start);                                           \
129
             struct_ptr = temp_ptr, temp_ptr = link_to_struct(temp_ptr->link_field.next, typeof(*temp_ptr), link_field))
130
 
131
#endif /* __LIST_H__ */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.