list.h
Go to the documentation of this file.
1 /***
2  * libccd
3  * ---------------------------------
4  * Copyright (c)2010 Daniel Fiser <danfis@danfis.cz>
5  *
6  *
7  * This file is part of libccd.
8  *
9  * Distributed under the OSI-approved BSD License (the "License");
10  * see accompanying file BDS-LICENSE for details or see
11  * <http://www.opensource.org/licenses/bsd-license.php>.
12  *
13  * This software is distributed WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  * See the License for more information.
16  */
17 
18 #ifndef __CCD_LIST_H__
19 #define __CCD_LIST_H__
20 
21 #include <string.h>
22 #include <ccd/compiler.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif /* __cplusplus */
27 
28 struct _ccd_list_t {
29  struct _ccd_list_t *next, *prev;
30 };
31 typedef struct _ccd_list_t ccd_list_t;
32 
33 
34 
41 #define ccdListEntry(ptr, type, member) \
42  ccd_container_of(ptr, type, member)
43 
47 #define ccdListForEach(list, item) \
48  for (item = (list)->next; \
49  _ccd_prefetch((item)->next), item != (list); \
50  item = (item)->next)
51 
55 #define ccdListForEachSafe(list, item, tmp) \
56  for (item = (list)->next, tmp = (item)->next; \
57  item != (list); \
58  item = tmp, tmp = (item)->next)
59 
66 #define ccdListForEachEntry(head, pos, postype, member) \
67  for (pos = ccdListEntry((head)->next, postype, member); \
68  _ccd_prefetch(pos->member.next), &pos->member != (head); \
69  pos = ccdListEntry(pos->member.next, postype, member))
70 
78 #define ccdListForEachEntrySafe(head, pos, postype, n, ntype, member) \
79  for (pos = ccdListEntry((head)->next, postype, member), \
80  n = ccdListEntry(pos->member.next, postype, member); \
81  &pos->member != (head); \
82  pos = n, n = ccdListEntry(n->member.next, ntype, member))
83 
84 
88 _ccd_inline void ccdListInit(ccd_list_t *l);
89 
90 _ccd_inline ccd_list_t *ccdListNext(ccd_list_t *l);
91 _ccd_inline ccd_list_t *ccdListPrev(ccd_list_t *l);
92 
96 _ccd_inline int ccdListEmpty(const ccd_list_t *head);
97 
101 _ccd_inline void ccdListAppend(ccd_list_t *l, ccd_list_t *item);
102 
106 _ccd_inline void ccdListDel(ccd_list_t *item);
107 
108 
109 
113 
114 _ccd_inline void ccdListInit(ccd_list_t *l)
115 {
116  l->next = l;
117  l->prev = l;
118 }
119 
121 {
122  return l->next;
123 }
124 
126 {
127  return l->prev;
128 }
129 
130 _ccd_inline int ccdListEmpty(const ccd_list_t *head)
131 {
132  return head->next == head;
133 }
134 
135 _ccd_inline void ccdListAppend(ccd_list_t *l, ccd_list_t *newl)
136 {
137  newl->prev = l->prev;
138  newl->next = l;
139  l->prev->next = newl;
140  l->prev = newl;
141 }
142 
143 _ccd_inline void ccdListDel(ccd_list_t *item)
144 {
145  item->next->prev = item->prev;
146  item->prev->next = item->next;
147  item->next = item;
148  item->prev = item;
149 }
150 
151 #ifdef __cplusplus
152 } /* extern "C" */
153 #endif /* __cplusplus */
154 
155 #endif /* __CCD_LIST_H__ */
ccdListInit
_ccd_inline void ccdListInit(ccd_list_t *l)
Definition: list.h:114
_ccd_list_t::next
struct _ccd_list_t * next
Definition: list.h:44
ccdListPrev
_ccd_inline ccd_list_t * ccdListPrev(ccd_list_t *l)
Definition: list.h:125
ccdListNext
_ccd_inline ccd_list_t * ccdListNext(ccd_list_t *l)
Definition: list.h:120
_ccd_list_t
Definition: list.h:28
_ccd_list_t::prev
struct _ccd_list_t * prev
Definition: list.h:44
ccdListEmpty
_ccd_inline int ccdListEmpty(const ccd_list_t *head)
Definition: list.h:130
ccdListDel
_ccd_inline void ccdListDel(ccd_list_t *item)
Definition: list.h:143
ccdListAppend
_ccd_inline void ccdListAppend(ccd_list_t *l, ccd_list_t *item)
Definition: list.h:135


fcl
Author(s):
autogenerated on Fri Jun 11 2021 02:38:03