Add a test to ensure simple branch handling
[cvsps-hv.git] / cbtcommon / list.h
blobcf4b3edefc01acf66fe3e2fcb05913a424061875
1 /*
2 * Copyright 2001, 2002, 2003 David Mansfield and Cobite, Inc.
3 * See COPYING file for license information
4 */
6 #ifndef _COMMON_LIST_H
7 #define _COMMON_LIST_H
9 /*
10 * Stolen from linux-2.1.131
11 * All comments from the original source unless otherwise noted
12 * Added: the CLEAR_LIST_NODE macro
16 * Simple doubly linked list implementation.
18 * Some of the internal functions ("__xxx") are useful when
19 * manipulating whole lists rather than single entries, as
20 * sometimes we already know the next/prev entries and we can
21 * generate better code by using them directly rather than
22 * using the generic single-entry routines.
25 #include "inline.h"
26 #include <stddef.h>
28 struct list_head {
29 struct list_head *next, *prev;
32 #define LIST_HEAD(name) \
33 struct list_head name = { &name, &name }
35 #define INIT_LIST_HEAD(ptr) do { \
36 (ptr)->next = (ptr); (ptr)->prev = (ptr); \
37 } while (0)
39 #define CLEAR_LIST_NODE(ptr) do { \
40 (ptr)->next = NULL; (ptr)->prev = NULL; \
41 } while (0)
44 * Insert a new entry between two known consecutive entries.
46 * This is only for internal list manipulation where we know
47 * the prev/next entries already!
49 static INLINE void __list_add(struct list_head *li,
50 struct list_head * prev,
51 struct list_head * next)
53 next->prev = li;
54 li->next = next;
55 li->prev = prev;
56 prev->next = li;
60 * Insert a new entry after the specified head..
62 static INLINE void list_add(struct list_head *li, struct list_head *head)
64 __list_add(li, head, head->next);
68 * Delete a list entry by making the prev/next entries
69 * point to each other.
71 * This is only for internal list manipulation where we know
72 * the prev/next entries already!
74 static INLINE void __list_del(struct list_head * prev,
75 struct list_head * next)
77 next->prev = prev;
78 prev->next = next;
81 static INLINE void list_del(struct list_head *entry)
83 __list_del(entry->prev, entry->next);
86 static INLINE int list_empty(struct list_head *head)
88 return head->next == head;
92 * Splice in "list" into "head"
94 static INLINE void list_splice(struct list_head *list, struct list_head *head)
96 struct list_head *first = list->next;
98 if (first != list) {
99 struct list_head *last = list->prev;
100 struct list_head *at = head->next;
102 first->prev = head;
103 head->next = first;
105 last->next = at;
106 at->prev = last;
110 #define list_entry(ptr, type, member) \
111 ((type *)((char *)(ptr)-offsetof(type, member)))
113 #endif /* _COMMON_LIST_H */