1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

dll2: add api for inserting afer existing member

This commit is contained in:
Andy Green 2021-12-26 16:22:37 +00:00
parent 8b16aa18c8
commit 65768cf3eb
2 changed files with 39 additions and 0 deletions

View file

@ -243,6 +243,9 @@ lws_dll2_owner_clear(struct lws_dll2_owner *d);
LWS_VISIBLE LWS_EXTERN void
lws_dll2_add_before(struct lws_dll2 *d, struct lws_dll2 *after);
LWS_VISIBLE LWS_EXTERN void
lws_dll2_add_insert(struct lws_dll2 *d, struct lws_dll2 *prev);
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));

View file

@ -136,6 +136,42 @@ lws_dll2_add_before(struct lws_dll2 *d, struct lws_dll2 *after)
owner->count++;
}
/* add us to the list that prev is in, just after him
*
* (Prev) [ <-> (Next) ]
* (Prev) <-> (ins) [ <-> (Next) ]
*
* use lws_dll2_add_head() instead if prev would be NULL
* */
void
lws_dll2_add_insert(struct lws_dll2 *d, struct lws_dll2 *prev)
{
lws_dll2_owner_t *owner = prev->owner;
if (!lws_dll2_is_detached(d)) {
assert(0); /* only wholly detached things can be added */
return;
}
if (lws_dll2_is_detached(prev)) {
assert(0); /* can't add after something detached */
return;
}
d->owner = owner;
d->next = prev->next;
d->prev = prev;
if (prev->next)
(prev->next)->prev = d;
prev->next = d;
if (!d->next)
owner->tail = d;
owner->count++;
}
void
lws_dll2_add_tail(struct lws_dll2 *d, struct lws_dll2_owner *owner)
{