diff options
author | Sander Vrijders <[email protected]> | 2017-01-09 16:40:40 +0100 |
---|---|---|
committer | Sander Vrijders <[email protected]> | 2017-01-09 16:40:40 +0100 |
commit | 6c1cfb990f56b2fa87500732cb4f0966616907c7 (patch) | |
tree | 4af3a0e2ce9fc12d7dc759803da70b7f570d6f8a /src/lib/list.c | |
parent | e56d24010287127fc6b9c9da8d1f7cf160c50253 (diff) | |
parent | 5273b0f5915956e49bcad4167cca2c1349e8816d (diff) | |
download | ouroboros-6c1cfb990f56b2fa87500732cb4f0966616907c7.tar.gz ouroboros-6c1cfb990f56b2fa87500732cb4f0966616907c7.zip |
Merged in dstaesse/ouroboros/be-list (pull request #340)
Updates to list and fixes LGPL license for library
Diffstat (limited to 'src/lib/list.c')
-rw-r--r-- | src/lib/list.c | 130 |
1 files changed, 39 insertions, 91 deletions
diff --git a/src/lib/list.c b/src/lib/list.c index 0f3493e3..2c577ea9 100644 --- a/src/lib/list.c +++ b/src/lib/list.c @@ -1,124 +1,72 @@ /* - * Ouroboros - Copyright (C) 2016 + * Ouroboros - Copyright (C) 2016 - 2017 * * Simple doubly linked list implementation. * - * Some of the internal functions ("__xxx") are useful when - * manipulating whole lists rather than single entries, as - * sometimes we already know the next/prev entries and we can - * generate better code by using them directly rather than - * using the generic single-entry routines. + * Sander Vrijders <[email protected]> + * Dimitri Staessense <[email protected]> * - * This file is from the Linux Kernel (include/linux/list.h) - * and modified by simply removing hardware prefetching of list items. - * Here by copyright, credits attributed to wherever they belong. - * Kulesh Shanmugasundaram (kulesh [squiggly] isis.poly.edu) + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. * - * Sander Vrijders <[email protected]> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, + * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA */ #include <ouroboros/list.h> -static void __list_add(struct list_head * new, - struct list_head * prev, - struct list_head * next) -{ - next->prev = new; - new->next = next; - new->prev = prev; - prev->next = new; -} - -void list_add(struct list_head * new, - struct list_head * head) -{ - __list_add(new, head, head->next); -} - -void list_add_tail(struct list_head * new, - struct list_head * head) -{ - __list_add(new, head->prev, head); -} - -static void __list_del(struct list_head * prev, - struct list_head * next) -{ - next->prev = prev; - prev->next = next; -} +#include <stddef.h> -void list_del(struct list_head * entry) +void list_head_init(struct list_head * h) { - __list_del(entry->prev, entry->next); - entry->next = (void *) 0; - entry->prev = (void *) 0; + h->nxt = h; + h->prv = h; } -void list_del_init(struct list_head * entry) +static void add_list(struct list_head * n, + struct list_head * prv, + struct list_head * nxt) { - __list_del(entry->prev, entry->next); - INIT_LIST_HEAD(entry); + nxt->prv = n; + n->nxt = nxt; + n->prv = prv; + prv->nxt = n; } -void list_move(struct list_head * list, - struct list_head * head) +static void del_list(struct list_head * prv, + struct list_head * nxt) { - __list_del(list->prev, list->next); - list_add(list, head); + nxt->prv = prv; + prv->nxt = nxt; } -void list_move_tail(struct list_head * list, - struct list_head * head) +void list_add(struct list_head * n, + struct list_head * h) { - __list_del(list->prev, list->next); - list_add_tail(list, head); + add_list(n, h, h->nxt); } -int list_empty(struct list_head * head) +void list_add_tail(struct list_head * n, + struct list_head * h) { - return head->next == head; -} - -static void __list_splice(struct list_head *list, - struct list_head *head) -{ - struct list_head *first = list->next; - struct list_head *last = list->prev; - struct list_head *at = head->next; - - first->prev = head; - head->next = first; - - last->next = at; - at->prev = last; + add_list(n, h->prv, h); } -void list_splice(struct list_head * list, - struct list_head * head) +void list_del(struct list_head * e) { - if (!list_empty(list)) - __list_splice(list, head); + del_list(e->prv, e->nxt); + e->nxt = e->prv = NULL; } -void list_splice_init(struct list_head * list, - struct list_head * head) +bool list_is_empty(struct list_head * h) { - if (!list_empty(list)) { - __list_splice(list, head); - INIT_LIST_HEAD(list); - } + return h->nxt == h; } |