00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00035 #ifndef __LIST_H__
00036 #define __LIST_H__
00037
00038 #include<unistd.h>
00039
00040 #ifndef true
00041 # define true 1
00042 #endif
00043 #ifndef false
00044 # define false 0
00045 #endif
00046
00047 typedef struct link link_t;
00048
00050 struct link {
00051 link_t *prev;
00052 link_t *next;
00053 };
00054
00059 #define LIST_INITIALIZE(name) link_t name = { .prev = &name, .next = &name }
00060
00067 static inline void link_initialize(link_t *link)
00068 {
00069 link->prev = NULL;
00070 link->next = NULL;
00071 }
00072
00079 static inline void list_initialize(link_t *head)
00080 {
00081 head->prev = head;
00082 head->next = head;
00083 }
00084
00092 static inline void list_prepend(link_t *link, link_t *head)
00093 {
00094 link->next = head->next;
00095 link->prev = head;
00096 head->next->prev = link;
00097 head->next = link;
00098 }
00099
00107 static inline void list_append(link_t *link, link_t *head)
00108 {
00109 link->prev = head->prev;
00110 link->next = head;
00111 head->prev->next = link;
00112 head->prev = link;
00113 }
00114
00121 static inline void list_remove(link_t *link)
00122 {
00123 link->next->prev = link->prev;
00124 link->prev->next = link->next;
00125 link_initialize(link);
00126 }
00127
00134 static inline int list_empty(link_t *head)
00135 {
00136 return head->next == head ? true : false;
00137 }
00138
00139
00150 static inline void headless_list_split_or_concat(link_t *part1, link_t *part2)
00151 {
00152 link_t *hlp;
00153
00154 part1->prev->next = part2;
00155 part2->prev->next = part1;
00156 hlp = part1->prev;
00157 part1->prev = part2->prev;
00158 part2->prev = hlp;
00159 }
00160
00161
00169 static inline void headless_list_split(link_t *part1, link_t *part2)
00170 {
00171 headless_list_split_or_concat(part1, part2);
00172 }
00173
00181 static inline void headless_list_concat(link_t *part1, link_t *part2)
00182 {
00183 headless_list_split_or_concat(part1, part2);
00184 }
00185
00186 #define list_get_instance(link,type,member) (type *)(((char *)(link))-((char *)&(((type *)NULL)->member)))
00187
00188 extern int list_member(const link_t *link, const link_t *head);
00189 extern void list_concat(link_t *head1, link_t *head2);
00190
00191 #endif
00192
00193