[PATCH 1/3] stailq: add stailq_insert function

Vladimir Davydov vdavydov.dev at gmail.com
Fri Jul 13 13:53:52 MSK 2018


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




More information about the Tarantool-patches mailing list