From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladimir Davydov Subject: [PATCH 1/3] stailq: add stailq_insert function Date: Fri, 13 Jul 2018 13:53:52 +0300 Message-Id: In-Reply-To: References: <22418dc475632b06aee6e8db562dc4467d6a0a31.1531065648.git.vdavydov.dev@gmail.com> In-Reply-To: References: To: kostja@tarantool.org Cc: tarantool-patches@freelists.org List-ID: The new function inserts a new item into the list at the specified postion. --- src/lib/salad/stailq.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/lib/salad/stailq.h b/src/lib/salad/stailq.h index 0f51ddb9..0d53369e 100644 --- a/src/lib/salad/stailq.h +++ b/src/lib/salad/stailq.h @@ -96,6 +96,19 @@ stailq_add_tail(struct stailq *head, struct stailq_entry *item) } /** + * Insert @item into list @head after @prev. + */ +inline static void +stailq_insert(struct stailq *head, struct stailq_entry *item, + struct stailq_entry *prev) +{ + item->next = prev->next; + prev->next = item; + if (item->next == NULL) + head->last = &item->next; +} + +/** * return first element */ inline static struct stailq_entry * @@ -234,6 +247,12 @@ stailq_cut_tail(struct stailq *head, struct stailq_entry *last, stailq_add_tail((head), &(item)->member) /** + * insert entry into list + */ +#define stailq_insert_entry(head, item, prev, member) \ + stailq_insert((head), &(item)->member, &(prev)->member) + +/** * foreach through list */ #define stailq_foreach(item, head) \ -- 2.11.0