X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Flist.c;h=e341d45bd432e5cfe1178260eba1c276629f9b1f;hb=0ef165ecb57943e17a8ee8270df68ffb8d032e29;hp=71790cc373e78a393e362f257ea10c540102556d;hpb=e0edde6fee279cdbbf3c179f5f50adaf0c7c7f1e;p=sliver-openvswitch.git diff --git a/lib/list.c b/lib/list.c index 71790cc37..e341d45bd 100644 --- a/lib/list.c +++ b/lib/list.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2009, 2010, 2011 Nicira, Inc. + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,6 @@ */ #include #include "list.h" -#include /* Initializes 'list' as an empty list. */ void @@ -47,8 +46,9 @@ list_insert(struct list *before, struct list *elem) void list_splice(struct list *before, struct list *first, struct list *last) { - if (first == last) + if (first == last) { return; + } last = last->prev; /* Cleanly remove 'first'...'last' from its current list. */ @@ -101,6 +101,20 @@ list_moved(struct list *list) list->prev->next = list->next->prev = list; } +/* Initializes 'dst' with the contents of 'src', compensating for moving it + * around in memory. The effect is that, if 'src' was the head of a list, now + * 'dst' is the head of a list containing the same elements. */ +void +list_move(struct list *dst, struct list *src) +{ + if (!list_is_empty(src)) { + *dst = *src; + list_moved(dst); + } else { + list_init(dst); + } +} + /* Removes 'elem' from its list and returns the element that followed it. Undefined behavior if 'elem' is not in a list. */ struct list * @@ -136,9 +150,9 @@ list_pop_back(struct list *list) struct list * list_front(const struct list *list_) { - struct list *list = (struct list *) list_; + struct list *list = CONST_CAST(struct list *, list_); - assert(!list_is_empty(list)); + ovs_assert(!list_is_empty(list)); return list->next; } @@ -147,9 +161,9 @@ list_front(const struct list *list_) struct list * list_back(const struct list *list_) { - struct list *list = (struct list *) list_; + struct list *list = CONST_CAST(struct list *, list_); - assert(!list_is_empty(list)); + ovs_assert(!list_is_empty(list)); return list->prev; } @@ -161,8 +175,9 @@ list_size(const struct list *list) const struct list *e; size_t cnt = 0; - for (e = list->next; e != list; e = e->next) + for (e = list->next; e != list; e = e->next) { cnt++; + } return cnt; }