Xenomai  3.0.8
lstLib.h
1 /*
2  * Copyright (C) 2008 Philippe Gerum <rpm@xenomai.org>.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13 
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  *
18  * This file satisfies the references within the emulator code
19  * mimicking a VxWorks-like API built upon the copperplate library.
20  *
21  * VxWorks is a registered trademark of Wind River Systems, Inc.
22  */
23 
24 #ifndef _XENOMAI_VXWORKS_LSTLIB_H
25 #define _XENOMAI_VXWORKS_LSTLIB_H
26 
27 #include <boilerplate/list.h>
28 #include <vxworks/types.h>
29 
30 typedef struct LIST {
31  struct pvlistobj list;
32  int count;
33 } LIST;
34 
35 typedef struct NODE {
36  struct pvholder link;
37  struct LIST *list;
38 } NODE;
39 
40 static inline void lstInit(LIST *l)
41 {
42  pvlist_init(&l->list);
43  l->count = 0;
44 }
45 
46 static inline void lstAdd(LIST *l, NODE *n)
47 {
48  pvholder_init(&n->link);
49  pvlist_append(&n->link, &l->list);
50  n->list = l;
51  l->count++;
52 }
53 
54 static inline int lstCount(LIST *l)
55 {
56  return l->count;
57 }
58 
59 static inline void lstDelete(LIST *l, NODE *n)
60 {
61  pvlist_remove(&n->link);
62  n->list = NULL;
63  l->count--;
64 }
65 
66 static inline NODE *lstFirst(LIST *l)
67 {
68  if (l == NULL || pvlist_empty(&l->list))
69  return NULL;
70 
71  return pvlist_first_entry(&l->list, struct NODE, link);
72 }
73 
74 static inline NODE *lstGet(LIST *l)
75 {
76  struct NODE *n;
77 
78  if (l == NULL || pvlist_empty(&l->list))
79  return NULL;
80 
81  n = pvlist_pop_entry(&l->list, struct NODE, link);
82  n->list = NULL;
83  l->count--;
84 
85  return n;
86 }
87 
88 static inline void lstInsert(LIST *l, NODE *nprev, NODE *n)
89 {
90  pvholder_init(&n->link);
91 
92  if (nprev == NULL)
93  pvlist_prepend(&n->link, &l->list);
94  else
95  pvlist_insert(&n->link, &nprev->link);
96 
97  n->list = l;
98  l->count++;
99 }
100 
101 static inline NODE *lstLast(LIST *l)
102 {
103  if (l == NULL || pvlist_empty(&l->list))
104  return NULL;
105 
106  return pvlist_last_entry(&l->list, struct NODE, link);
107 }
108 
109 static inline NODE *lstNext(NODE *n)
110 {
111  if (n->list == NULL || &n->link == n->list->list.head.prev)
112  return NULL;
113 
114  return container_of(n->link.next, struct NODE, link);
115 }
116 
117 static inline NODE *lstPrevious(NODE *n)
118 {
119  if (n->list == NULL || &n->link == n->list->list.head.next)
120  return NULL;
121 
122  return container_of(n->link.prev, struct NODE, link);
123 }
124 
125 static inline void lstFree(LIST *l)
126 {
127  lstInit(l);
128 }
129 
130 #ifdef __cplusplus
131 extern "C" {
132 #endif
133 
134 void lstExtract(LIST *lsrc, NODE *nstart, NODE *nend, LIST *ldst);
135 
136 NODE *lstNth(LIST *l, int nodenum);
137 
138 NODE *lstNStep(NODE *n, int steps);
139 
140 int lstFind(LIST *l, NODE *n);
141 
142 void lstConcat(LIST *ldst, LIST *lsrc);
143 
144 #ifdef __cplusplus
145 }
146 #endif
147 
148 #endif /* !_XENOMAI_VXWORKS_LSTLIB_H */