libwebsockets
Lightweight C library for HTML5 websockets
Loading...
Searching...
No Matches
lws-dll2.h
Go to the documentation of this file.
1/*
2 * libwebsockets - small server side websockets and web server implementation
3 *
4 * Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 */
24
31
48#define lws_start_foreach_ll(type, it, start)\
49{ \
50 type it = start; \
51 while (it) { \
52 int _c_##it = 0, _b_##it = 0; \
53 for (; !_c_##it; _c_##it = 1) {
54
68
69#define lws_end_foreach_ll(it, nxt) \
70 _b_##it = 1; \
71 } \
72 if (!_b_##it) break; \
73 it = it->nxt; \
74 } \
75}
76
96#define lws_start_foreach_ll_safe(type, it, start, nxt)\
97{ \
98 type next_##it; \
99 for (type it = start; it && ((next_##it = it->nxt), 1); it = next_##it) {
100
114
115#define lws_end_foreach_ll_safe(it) \
116 } \
117}
118
139#define lws_start_foreach_llp(type, it, start)\
140{ \
141 type it = &(start); \
142 while (*(it)) { \
143 int _c_##it = 0, _b_##it = 0; \
144 for (; !_c_##it; _c_##it = 1) {
145
146#define lws_start_foreach_llp_safe(type, it, start, nxt)\
147{ \
148 type next; \
149 for (type it = &(start); *(it) && ((next = &((*(it))->nxt)), 1); it = next) {
150
164
165#define lws_end_foreach_llp(it, nxt) \
166 _b_##it = 1; \
167 } \
168 if (!_b_##it) break; \
169 it = &(*(it))->nxt; \
170 } \
171}
172
173#define lws_end_foreach_llp_safe(it) \
174 } \
175}
176
177#define lws_ll_fwd_insert(\
178 ___new_object, /* pointer to new object */ \
179 ___m_list, /* member for next list object ptr */ \
180 ___list_head /* list head */ \
181 ) {\
182 ___new_object->___m_list = ___list_head; \
183 ___list_head = ___new_object; \
184 }
185
186#define lws_ll_fwd_remove(\
187 ___type, /* type of listed object */ \
188 ___m_list, /* member for next list object ptr */ \
189 ___target, /* object to remove from list */ \
190 ___list_head /* list head */ \
191 ) { \
192 lws_start_foreach_llp(___type **, ___ppss, ___list_head) { \
193 if (*___ppss == ___target) { \
194 *___ppss = ___target->___m_list; \
195 break; \
196 } \
197 } lws_end_foreach_llp(___ppss, ___m_list); \
198 }
199
200
201/*
202 * doubly linked-list
203 */
204
205/*
206 * lws_dll2_owner / lws_dll2 : more capable version of lws_dll. Differences:
207 *
208 * - there's an explicit lws_dll2_owner struct which holds head, tail and
209 * count of members.
210 *
211 * - list members all hold a pointer to their owner. So user code does not
212 * have to track anything about exactly what lws_dll2_owner list the object
213 * is a member of.
214 *
215 * - you can use lws_dll unless you want the member count or the ability to
216 * not track exactly which list it's on.
217 *
218 * - layout is compatible with lws_dll (but lws_dll apis will not update the
219 * new stuff)
220 */
221
222
223struct lws_dll2;
224struct lws_dll2_owner;
225
226typedef struct lws_dll2 {
227 struct lws_dll2 *prev;
228 struct lws_dll2 *next;
231
238
241
242static LWS_INLINE const struct lws_dll2_owner *
243lws_dll2_owner(const struct lws_dll2 *d) { return d->owner; }
244
245static LWS_INLINE struct lws_dll2 *
246lws_dll2_get_head(struct lws_dll2_owner *owner) { return owner->head; }
247
248static LWS_INLINE struct lws_dll2 *
249lws_dll2_get_tail(struct lws_dll2_owner *owner) { return owner->tail; }
250
253
256
259
260typedef int (*lws_dll2_foreach_cb_t)(struct lws_dll2 *d, void *user);
261
265
268
271
273lws_dll2_add_before(struct lws_dll2 *d, struct lws_dll2 *after);
274
277
280 int (*compare)(const lws_dll2_t *d, const lws_dll2_t *i));
281
284 int (*compare3)(void *priv, const lws_dll2_t *d,
285 const lws_dll2_t *i));
286
288_lws_dll2_search_sz_pl(lws_dll2_owner_t *own, const char *name, size_t namelen,
289 size_t dll2_ofs, size_t ptr_ofs);
290
291/*
292 * Searches objects in an owner list linearly and returns one with a given
293 * member C-string matching a supplied length-provided string if it exists, else
294 * NULL.
295 */
296
297#define lws_dll2_search_sz_pl(own, name, namelen, type, membd2list, membptr) \
298 ((type *)_lws_dll2_search_sz_pl(own, name, namelen, \
299 offsetof(type, membd2list), \
300 offsetof(type, membptr)))
301
302#if defined(_DEBUG)
303void
304lws_dll2_describe(struct lws_dll2_owner *owner, const char *desc);
305#else
306#define lws_dll2_describe(x, y)
307#endif
308
309/*
310 * these are safe against the current container object getting deleted,
311 * since the hold his next in a temp and go to that next. ___tmp is
312 * the temp.
313 */
314
315#define lws_start_foreach_dll_safe(___type, ___it, ___tmp, ___start) \
316{ \
317 ___type ___tmp; \
318 for (___type ___it = ___start; ___it && (((___tmp) = (___it)->next), 1); ___it = ___tmp) {
319
320#define lws_end_foreach_dll_safe(___it, ___tmp) \
321 } \
322}
323
324#define lws_start_foreach_dll(___type, ___it, ___start) \
325{ \
326 for (___type ___it = ___start; ___it; ___it = (___it)->next) {
327
328#define lws_end_foreach_dll(___it) \
329 } \
330}
331
333
struct lws_dll2 * tail
Definition lws-dll2.h:233
struct lws_dll2 * next
Definition lws-dll2.h:228
struct lws_dll2_owner * owner
Definition lws-dll2.h:229
struct lws_dll2 * prev
Definition lws-dll2.h:227
struct lws_dll2 * head
Definition lws-dll2.h:234
uint32_t count
Definition lws-dll2.h:236
struct lws_dll2 lws_dll2_t
LWS_VISIBLE LWS_EXTERN void lws_dll2_add_tail(struct lws_dll2 *d, struct lws_dll2_owner *owner)
LWS_VISIBLE LWS_EXTERN void lws_dll2_owner_clear(struct lws_dll2_owner *d)
LWS_VISIBLE LWS_EXTERN void lws_dll2_add_sorted_priv(lws_dll2_t *d, lws_dll2_owner_t *own, void *priv, int(*compare3)(void *priv, const lws_dll2_t *d, const lws_dll2_t *i))
#define lws_dll2_describe(x, y)
Definition lws-dll2.h:306
LWS_VISIBLE LWS_EXTERN void lws_dll2_add_sorted(lws_dll2_t *d, lws_dll2_owner_t *own, int(*compare)(const lws_dll2_t *d, const lws_dll2_t *i))
struct lws_dll2_owner lws_dll2_owner_t
LWS_VISIBLE LWS_EXTERN void lws_dll2_add_insert(struct lws_dll2 *d, struct lws_dll2 *prev)
LWS_VISIBLE LWS_EXTERN void * _lws_dll2_search_sz_pl(lws_dll2_owner_t *own, const char *name, size_t namelen, size_t dll2_ofs, size_t ptr_ofs)
LWS_VISIBLE LWS_EXTERN void lws_dll2_add_before(struct lws_dll2 *d, struct lws_dll2 *after)
int(* lws_dll2_foreach_cb_t)(struct lws_dll2 *d, void *user)
Definition lws-dll2.h:260
LWS_VISIBLE LWS_EXTERN int lws_dll2_is_detached(const struct lws_dll2 *d)
LWS_VISIBLE LWS_EXTERN void lws_dll2_remove(struct lws_dll2 *d)
LWS_VISIBLE LWS_EXTERN void lws_dll2_clear(struct lws_dll2 *d)
LWS_VISIBLE LWS_EXTERN int lws_dll2_foreach_safe(struct lws_dll2_owner *owner, void *user, lws_dll2_foreach_cb_t cb)
LWS_VISIBLE LWS_EXTERN void lws_dll2_add_head(struct lws_dll2 *d, struct lws_dll2_owner *owner)
unsigned int uint32_t
#define LWS_INLINE
#define LWS_EXTERN
#define LWS_VISIBLE