Subversion Repositories HelenOS

Rev

Rev 3022 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3022 Rev 4420
Line 35... Line 35...
35
#ifndef LIBC_LIST_H_
35
#ifndef LIBC_LIST_H_
36
#define LIBC_LIST_H_
36
#define LIBC_LIST_H_
37
 
37
 
38
#include <unistd.h>
38
#include <unistd.h>
39
 
39
 
40
#ifndef true
-
 
41
# define true 1
-
 
42
#endif
-
 
43
#ifndef false
-
 
44
# define false 0
-
 
45
#endif
-
 
46
 
-
 
47
typedef struct link link_t;
-
 
48
 
-
 
49
/** Doubly linked list head and link type. */
40
/** Doubly linked list head and link type. */
50
struct link {
41
typedef struct link {
51
    link_t *prev;   /**< Pointer to the previous item in the list. */
42
    struct link *prev;  /**< Pointer to the previous item in the list. */
52
    link_t *next;   /**< Pointer to the next item in the list. */
43
    struct link *next;  /**< Pointer to the next item in the list. */
53
};
44
} link_t;
54
 
45
 
55
/** Declare and initialize statically allocated list.
46
/** Declare and initialize statically allocated list.
56
 *
47
 *
57
 * @param name Name of the new statically allocated list.
48
 * @param name Name of the new statically allocated list.
58
 */
49
 */
59
#define LIST_INITIALIZE(name)       link_t name = { .prev = &name, .next = &name }
50
#define LIST_INITIALIZE(name)  link_t name = { \
-
 
51
    .prev = &name, \
-
 
52
    .next = &name \
-
 
53
}
60
 
54
 
61
/** Initialize doubly-linked circular list link
55
/** Initialize doubly-linked circular list link
62
 *
56
 *
63
 * Initialize doubly-linked list link.
57
 * Initialize doubly-linked list link.
64
 *
58
 *
Line 143... Line 137...
143
 *
137
 *
144
 * @param head Pointer to link_t structure representing head of the list.
138
 * @param head Pointer to link_t structure representing head of the list.
145
 */
139
 */
146
static inline int list_empty(link_t *head)
140
static inline int list_empty(link_t *head)
147
{
141
{
148
    return head->next == head ? true : false;
142
    return ((head->next == head) ? 1 : 0);
149
}
143
}
150
 
144
 
151
 
145
 
152
/** Split or concatenate headless doubly-linked circular list
146
/** Split or concatenate headless doubly-linked circular list
153
 *
147
 *
Line 159... Line 153...
159
 * @param part1 Pointer to link_t structure leading the first (half of the headless) list.
153
 * @param part1 Pointer to link_t structure leading the first (half of the headless) list.
160
 * @param part2 Pointer to link_t structure leading the second (half of the headless) list.
154
 * @param part2 Pointer to link_t structure leading the second (half of the headless) list.
161
 */
155
 */
162
static inline void headless_list_split_or_concat(link_t *part1, link_t *part2)
156
static inline void headless_list_split_or_concat(link_t *part1, link_t *part2)
163
{
157
{
164
    link_t *hlp;
-
 
165
 
-
 
166
    part1->prev->next = part2;
158
    part1->prev->next = part2;
167
    part2->prev->next = part1; 
159
    part2->prev->next = part1;
-
 
160
   
168
    hlp = part1->prev;
161
    link_t *hlp = part1->prev;
-
 
162
   
169
    part1->prev = part2->prev;
163
    part1->prev = part2->prev;
170
    part2->prev = hlp;
164
    part2->prev = hlp;
171
}
165
}
172
 
166
 
173
 
167
 
Line 193... Line 187...
193
static inline void headless_list_concat(link_t *part1, link_t *part2)
187
static inline void headless_list_concat(link_t *part1, link_t *part2)
194
{
188
{
195
    headless_list_split_or_concat(part1, part2);
189
    headless_list_split_or_concat(part1, part2);
196
}
190
}
197
 
191
 
198
#define list_get_instance(link,type,member) (type *)(((char *)(link))-((char *)&(((type *)NULL)->member)))
192
#define list_get_instance(link, type, member)  ((type *) (((void *)(link)) - ((void *) &(((type *) NULL)->member))))
199
 
193
 
200
extern int list_member(const link_t *link, const link_t *head);
194
extern int list_member(const link_t *link, const link_t *head);
201
extern void list_concat(link_t *head1, link_t *head2);
195
extern void list_concat(link_t *head1, link_t *head2);
-
 
196
extern unsigned int list_count(const link_t *link);
202
 
197
 
203
#endif
198
#endif
204
 
199
 
205
/** @}
200
/** @}
206
 */
201
 */