Rev 532 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 532 | Rev 534 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2001-2004 Jakub Jermar |
2 | * Copyright (C) 2001-2004 Jakub Jermar |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | #ifndef __LIST_H__ |
29 | #ifndef __LIST_H__ |
30 | #define __LIST_H__ |
30 | #define __LIST_H__ |
31 | 31 | ||
32 | #include <arch/types.h> |
32 | #include <arch/types.h> |
33 | #include <typedefs.h> |
33 | #include <typedefs.h> |
34 | 34 | ||
35 | struct link { |
35 | struct link { |
36 | link_t *prev; |
36 | link_t *prev; |
37 | link_t *next; |
37 | link_t *next; |
38 | }; |
38 | }; |
39 | 39 | ||
40 | /** Initialize doubly-linked circular list link |
40 | /** Initialize doubly-linked circular list link |
41 | * |
41 | * |
42 | * Initialize doubly-linked list link. |
42 | * Initialize doubly-linked list link. |
43 | * |
43 | * |
44 | * @param link Pointer to link_t structure to be initialized. |
44 | * @param link Pointer to link_t structure to be initialized. |
45 | */ |
45 | */ |
46 | static inline void link_initialize(link_t *link) |
46 | static inline void link_initialize(link_t *link) |
47 | { |
47 | { |
48 | link->prev = NULL; |
48 | link->prev = NULL; |
49 | link->next = NULL; |
49 | link->next = NULL; |
50 | } |
50 | } |
51 | 51 | ||
52 | /** Initialize doubly-linked circular list |
52 | /** Initialize doubly-linked circular list |
53 | * |
53 | * |
54 | * Initialize doubly-linked circular list. |
54 | * Initialize doubly-linked circular list. |
55 | * |
55 | * |
56 | * @param head Pointer to link_t structure representing head of the list. |
56 | * @param head Pointer to link_t structure representing head of the list. |
57 | */ |
57 | */ |
58 | static inline void list_initialize(link_t *head) |
58 | static inline void list_initialize(link_t *head) |
59 | { |
59 | { |
60 | head->prev = head; |
60 | head->prev = head; |
61 | head->next = head; |
61 | head->next = head; |
62 | } |
62 | } |
63 | 63 | ||
64 | /** Add item to the beginning of doubly-linked circular list |
64 | /** Add item to the beginning of doubly-linked circular list |
65 | * |
65 | * |
66 | * Add item to the beginning of doubly-linked circular list. |
66 | * Add item to the beginning of doubly-linked circular list. |
67 | * |
67 | * |
68 | * @param link Pointer to link_t structure to be added. |
68 | * @param link Pointer to link_t structure to be added. |
69 | * @param head Pointer to link_t structure representing head of the list. |
69 | * @param head Pointer to link_t structure representing head of the list. |
70 | */ |
70 | */ |
71 | static inline void list_prepend(link_t *link, link_t *head) |
71 | static inline void list_prepend(link_t *link, link_t *head) |
72 | { |
72 | { |
73 | link->next = head->next; |
73 | link->next = head->next; |
74 | link->prev = head; |
74 | link->prev = head; |
75 | head->next->prev = link; |
75 | head->next->prev = link; |
76 | head->next = link; |
76 | head->next = link; |
77 | } |
77 | } |
78 | 78 | ||
79 | /** Add item to the end of doubly-linked circular list |
79 | /** Add item to the end of doubly-linked circular list |
80 | * |
80 | * |
81 | * Add item to the end of doubly-linked circular list. |
81 | * Add item to the end of doubly-linked circular list. |
82 | * |
82 | * |
83 | * @param link Pointer to link_t structure to be added. |
83 | * @param link Pointer to link_t structure to be added. |
84 | * @param head Pointer to link_t structure representing head of the list. |
84 | * @param head Pointer to link_t structure representing head of the list. |
85 | */ |
85 | */ |
86 | static inline void list_append(link_t *link, link_t *head) |
86 | static inline void list_append(link_t *link, link_t *head) |
87 | { |
87 | { |
88 | link->prev = head->prev; |
88 | link->prev = head->prev; |
89 | link->next = head; |
89 | link->next = head; |
90 | head->prev->next = link; |
90 | head->prev->next = link; |
91 | head->prev = link; |
91 | head->prev = link; |
92 | } |
92 | } |
93 | 93 | ||
94 | /** Remove item from doubly-linked circular list |
94 | /** Remove item from doubly-linked circular list |
95 | * |
95 | * |
96 | * Remove item from doubly-linked circular list. |
96 | * Remove item from doubly-linked circular list. |
97 | * |
97 | * |
98 | * @param link Pointer to link_t structure to be removed from the list it is contained in. |
98 | * @param link Pointer to link_t structure to be removed from the list it is contained in. |
99 | */ |
99 | */ |
100 | static inline void list_remove(link_t *link) |
100 | static inline void list_remove(link_t *link) |
101 | { |
101 | { |
102 | link->next->prev = link->prev; |
102 | link->next->prev = link->prev; |
103 | link->prev->next = link->next; |
103 | link->prev->next = link->next; |
104 | link_initialize(link); |
104 | link_initialize(link); |
105 | } |
105 | } |
106 | 106 | ||
107 | /** Query emptiness of doubly-linked circular list |
107 | /** Query emptiness of doubly-linked circular list |
108 | * |
108 | * |
109 | * Query emptiness of doubly-linked circular list. |
109 | * Query emptiness of doubly-linked circular list. |
110 | * |
110 | * |
111 | * @param head Pointer to link_t structure representing head of the list. |
111 | * @param head Pointer to link_t structure representing head of the list. |
112 | */ |
112 | */ |
113 | static inline bool list_empty(link_t *head) |
113 | static inline bool list_empty(link_t *head) |
114 | { |
114 | { |
115 | return head->next == head ? true : false; |
115 | return head->next == head ? true : false; |
116 | } |
116 | } |
117 | 117 | ||
118 | 118 | ||
119 | /** Split or concatenate headless doubly-linked circular list |
119 | /** Split or concatenate headless doubly-linked circular list |
120 | * |
120 | * |
121 | * Split or concatenate headless doubly-linked circular list. |
121 | * Split or concatenate headless doubly-linked circular list. |
122 | * |
122 | * |
123 | * Note that the algorithm works both directions: |
123 | * Note that the algorithm works both directions: |
124 | * concatenates splitted lists and splits concatenated lists. |
124 | * concatenates splitted lists and splits concatenated lists. |
125 | * |
125 | * |
126 | * @param part1 Pointer to link_t structure leading the first (half of the headless) list. |
126 | * @param part1 Pointer to link_t structure leading the first (half of the headless) list. |
127 | * @param part2 Pointer to link_t structure leading the second (half of the headless) list. |
127 | * @param part2 Pointer to link_t structure leading the second (half of the headless) list. |
128 | */ |
128 | */ |
129 | static inline void headless_list_split_or_concat(link_t *part1, link_t *part2) |
129 | static inline void headless_list_split_or_concat(link_t *part1, link_t *part2) |
130 | { |
130 | { |
131 | link_t *hlp; |
131 | link_t *hlp; |
132 | 132 | ||
133 | part1->prev->next = part2; |
133 | part1->prev->next = part2; |
134 | part2->prev->next = part1; |
134 | part2->prev->next = part1; |
135 | hlp = part1->prev; |
135 | hlp = part1->prev; |
136 | part1->prev = part2->prev; |
136 | part1->prev = part2->prev; |
137 | part2->prev = hlp; |
137 | part2->prev = hlp; |
138 | } |
138 | } |
139 | 139 | ||
140 | 140 | ||
141 | /** Split headless doubly-linked circular list |
141 | /** Split headless doubly-linked circular list |
142 | * |
142 | * |
143 | * Split headless doubly-linked circular list. |
143 | * Split headless doubly-linked circular list. |
144 | * |
144 | * |
145 | * @param part1 Pointer to link_t structure leading the first half of the headless list. |
145 | * @param part1 Pointer to link_t structure leading the first half of the headless list. |
146 | * @param part2 Pointer to link_t structure leading the second half of the headless list. |
146 | * @param part2 Pointer to link_t structure leading the second half of the headless list. |
147 | */ |
147 | */ |
148 | static inline void headless_list_split(link_t *part1, link_t *part2) |
148 | static inline void headless_list_split(link_t *part1, link_t *part2) |
149 | { |
149 | { |
150 | headless_list_split_or_concat(part1, part2); |
150 | headless_list_split_or_concat(part1, part2); |
151 | } |
151 | } |
152 | 152 | ||
153 | /** Concatenate two headless doubly-linked circular lists |
153 | /** Concatenate two headless doubly-linked circular lists |
154 | * |
154 | * |
155 | * Concatenate two headless doubly-linked circular lists. |
155 | * Concatenate two headless doubly-linked circular lists. |
156 | * |
156 | * |
157 | * @param part1 Pointer to link_t structure leading the first headless list. |
157 | * @param part1 Pointer to link_t structure leading the first headless list. |
158 | * @param part2 Pointer to link_t structure leading the second headless list. |
158 | * @param part2 Pointer to link_t structure leading the second headless list. |
159 | */ |
159 | */ |
160 | static inline void headless_list_concat(link_t *part1, link_t *part2) |
160 | static inline void headless_list_concat(link_t *part1, link_t *part2) |
161 | { |
161 | { |
162 | headless_list_split_or_concat(part1, part2); |
162 | headless_list_split_or_concat(part1, part2); |
163 | } |
163 | } |
164 | 164 | ||
165 | #define list_get_instance(link,type,member) (type *)(((__u8*)(link))-((__u8*)&(((type *)NULL)->member))) |
165 | #define list_get_instance(link,type,member) (type *)(((__u8*)(link))-((__u8*)&(((type *)NULL)->member))) |
166 | 166 | ||
167 | extern bool list_member(const link_t *link, const link_t *head); |
167 | extern bool list_member(const link_t *link, const link_t *head); |
168 | extern void list_concat(link_t *head1, link_t *head2); |
168 | extern void list_concat(link_t *head1, link_t *head2); |
169 | 169 | ||
170 | #endif |
170 | #endif |
171 | 171 |