* UCW Library -- Circular Linked Lists
*
* (c) 2003--2010 Martin Mares <mj@ucw.cz>
+ * (c) 2017 Pavel Charvat <pchar@ucw.cz>
*
* This software may be freely distributed and used according to the terms
* of the GNU Lesser General Public License.
}
}
+/**
+ * Merge two lists by inserting the list @what in front of all other nodes in a different list @l.
+ * The first list is then cleared.
+ **/
+static inline void clist_add_list_head(clist *l, clist *what)
+{
+ clist_insert_list_after(what, &l->head);
+}
+
+/**
+ * Merge two lists by inserting the list @what after all other nodes in a different list @l.
+ * The first list is then cleared.
+ **/
+static inline void clist_add_list_tail(clist *l, clist *what)
+{
+ clist_insert_list_after(what, l->head.prev);
+}
+
/**
* Move all items from a source list to a destination list. The source list
* becomes empty, the original contents of the destination list are destroyed.
main_prepare_delete(m);
// Close all files
- clist_insert_list_after(&m->file_active_list, m->file_list.head.prev);
+ clist_add_list_tail(&m->file_list, &m->file_active_list);
#ifdef CONFIG_UCW_EPOLL
- clist_insert_list_after(&m->file_recalc_list, m->file_list.head.prev);
+ clist_add_list_tail(&m->file_list, &m->file_recalc_list);
#endif
CLIST_FOR_EACH(struct main_file *, f, m->file_list)
close(f->fd);
* UCW Library -- Single-Linked Lists
*
* (c) 2005 Martin Mares <mj@ucw.cz>
+ * (c) 2017 Pavel Charvat <pchar@ucw.cz>
*
* This software may be freely distributed and used according to the terms
* of the GNU Lesser General Public License.
slist_remove(l, l->last);
}
+/**
+ * Merge two lists by inserting the list @what in front of all other nodes in a different list @l.
+ * The first list is then cleared.
+ **/
+static inline void slist_add_list_head(slist *l, slist *what)
+{
+ if (!slist_empty(what))
+ {
+ if (!slist_empty(l))
+ what->last->next = l->head.next;
+ else
+ l->last = what->last;
+ l->head.next = what->head.next;
+ slist_init(what);
+ }
+}
+
+/**
+ * Merge two lists by inserting the list @what after all other nodes in a different list @l.
+ * The first list is then cleared.
+ **/
+static inline void slist_add_list_tail(slist *l, slist *what)
+{
+ if (!slist_empty(what))
+ {
+ if (!slist_empty(l))
+ l->last->next = what->head.next;
+ else
+ l->head.next = what->head.next;
+ l->last = what->last;
+ slist_init(what);
+ }
+}
+
+/**
+ * Move all items from a source list to a destination list. The source list
+ * becomes empty, the original contents of the destination list are destroyed.
+ **/
+static inline void slist_move(slist *to, slist *from)
+{
+ to->head.next = from->head.next;
+ to->last = from->last;
+ slist_init(from);
+}
+
/**
* Compute the number of nodes in @l. Beware linear time complexity.
**/