Skip to content

Commit

Permalink
list: Rename all functions in list.h with ovs_ prefix.
Browse files Browse the repository at this point in the history
This attempts to prevent namespace collisions with other list libraries

Signed-off-by: Ben Warren <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
Ben Warren authored and blp committed Mar 30, 2016
1 parent b19bab5 commit 417e7e6
Show file tree
Hide file tree
Showing 67 changed files with 611 additions and 611 deletions.
94 changes: 47 additions & 47 deletions include/openvswitch/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,33 +43,33 @@ static const struct ovs_list OVS_LIST_POISON =
(struct ovs_list) { (struct ovs_list *) (uintptr_t) 0xccccccccccccccccULL, \
(struct ovs_list *) (uintptr_t) 0xccccccccccccccccULL }

static inline void list_init(struct ovs_list *);
static inline void list_poison(struct ovs_list *);
static inline void ovs_list_init(struct ovs_list *);
static inline void ovs_list_poison(struct ovs_list *);

/* List insertion. */
static inline void list_insert(struct ovs_list *, struct ovs_list *);
static inline void list_splice(struct ovs_list *before, struct ovs_list *first,
static inline void ovs_list_insert(struct ovs_list *, struct ovs_list *);
static inline void ovs_list_splice(struct ovs_list *before, struct ovs_list *first,
struct ovs_list *last);
static inline void list_push_front(struct ovs_list *, struct ovs_list *);
static inline void list_push_back(struct ovs_list *, struct ovs_list *);
static inline void list_replace(struct ovs_list *, const struct ovs_list *);
static inline void list_moved(struct ovs_list *, const struct ovs_list *orig);
static inline void list_move(struct ovs_list *dst, struct ovs_list *src);
static inline void ovs_list_push_front(struct ovs_list *, struct ovs_list *);
static inline void ovs_list_push_back(struct ovs_list *, struct ovs_list *);
static inline void ovs_list_replace(struct ovs_list *, const struct ovs_list *);
static inline void ovs_list_moved(struct ovs_list *, const struct ovs_list *orig);
static inline void ovs_list_move(struct ovs_list *dst, struct ovs_list *src);

/* List removal. */
static inline struct ovs_list *list_remove(struct ovs_list *);
static inline struct ovs_list *list_pop_front(struct ovs_list *);
static inline struct ovs_list *list_pop_back(struct ovs_list *);
static inline struct ovs_list *ovs_list_remove(struct ovs_list *);
static inline struct ovs_list *ovs_list_pop_front(struct ovs_list *);
static inline struct ovs_list *ovs_list_pop_back(struct ovs_list *);

/* List elements. */
static inline struct ovs_list *list_front(const struct ovs_list *);
static inline struct ovs_list *list_back(const struct ovs_list *);
static inline struct ovs_list *ovs_list_front(const struct ovs_list *);
static inline struct ovs_list *ovs_list_back(const struct ovs_list *);

/* List properties. */
static inline size_t list_size(const struct ovs_list *);
static inline bool list_is_empty(const struct ovs_list *);
static inline bool list_is_singleton(const struct ovs_list *);
static inline bool list_is_short(const struct ovs_list *);
static inline size_t ovs_list_size(const struct ovs_list *);
static inline bool ovs_list_is_empty(const struct ovs_list *);
static inline bool ovs_list_is_singleton(const struct ovs_list *);
static inline bool ovs_list_is_short(const struct ovs_list *);

#define LIST_FOR_EACH(ITER, MEMBER, LIST) \
for (INIT_CONTAINER(ITER, (LIST)->next, MEMBER); \
Expand All @@ -94,29 +94,29 @@ static inline bool list_is_short(const struct ovs_list *);
: 0); \
(ITER) = (NEXT))
#define LIST_FOR_EACH_POP(ITER, MEMBER, LIST) \
while (!list_is_empty(LIST) \
&& (INIT_CONTAINER(ITER, list_pop_front(LIST), MEMBER), 1))
while (!ovs_list_is_empty(LIST) \
&& (INIT_CONTAINER(ITER, ovs_list_pop_front(LIST), MEMBER), 1))

/* Inline implementations. */

/* Initializes 'list' as an empty list. */
static inline void
list_init(struct ovs_list *list)
ovs_list_init(struct ovs_list *list)
{
list->next = list->prev = list;
}

/* Initializes 'list' with pointers that will (probably) cause segfaults if
* dereferenced and, better yet, show up clearly in a debugger. */
static inline void
list_poison(struct ovs_list *list)
ovs_list_poison(struct ovs_list *list)
{
*list = OVS_LIST_POISON;
}

/* Inserts 'elem' just before 'before'. */
static inline void
list_insert(struct ovs_list *before, struct ovs_list *elem)
ovs_list_insert(struct ovs_list *before, struct ovs_list *elem)
{
elem->prev = before->prev;
elem->next = before;
Expand All @@ -127,7 +127,7 @@ list_insert(struct ovs_list *before, struct ovs_list *elem)
/* Removes elements 'first' though 'last' (exclusive) from their current list,
then inserts them just before 'before'. */
static inline void
list_splice(struct ovs_list *before, struct ovs_list *first, struct ovs_list *last)
ovs_list_splice(struct ovs_list *before, struct ovs_list *first, struct ovs_list *last)
{
if (first == last) {
return;
Expand All @@ -148,23 +148,23 @@ list_splice(struct ovs_list *before, struct ovs_list *first, struct ovs_list *la
/* Inserts 'elem' at the beginning of 'list', so that it becomes the front in
'list'. */
static inline void
list_push_front(struct ovs_list *list, struct ovs_list *elem)
ovs_list_push_front(struct ovs_list *list, struct ovs_list *elem)
{
list_insert(list->next, elem);
ovs_list_insert(list->next, elem);
}

/* Inserts 'elem' at the end of 'list', so that it becomes the back in
* 'list'. */
static inline void
list_push_back(struct ovs_list *list, struct ovs_list *elem)
ovs_list_push_back(struct ovs_list *list, struct ovs_list *elem)
{
list_insert(list, elem);
ovs_list_insert(list, elem);
}

/* Puts 'elem' in the position currently occupied by 'position'.
* Afterward, 'position' is not part of a list. */
static inline void
list_replace(struct ovs_list *element, const struct ovs_list *position)
ovs_list_replace(struct ovs_list *element, const struct ovs_list *position)
{
element->next = position->next;
element->next->prev = element;
Expand All @@ -181,10 +181,10 @@ list_replace(struct ovs_list *element, const struct ovs_list *position)
* language lawyer sense, this still yields undefined behavior, but it works
* with actual compilers.) */
static inline void
list_moved(struct ovs_list *list, const struct ovs_list *orig)
ovs_list_moved(struct ovs_list *list, const struct ovs_list *orig)
{
if (list->next == orig) {
list_init(list);
ovs_list_init(list);
} else {
list->prev->next = list->next->prev = list;
}
Expand All @@ -194,16 +194,16 @@ list_moved(struct ovs_list *list, const struct ovs_list *orig)
* 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. */
static inline void
list_move(struct ovs_list *dst, struct ovs_list *src)
ovs_list_move(struct ovs_list *dst, struct ovs_list *src)
{
*dst = *src;
list_moved(dst, src);
ovs_list_moved(dst, src);
}

/* Removes 'elem' from its list and returns the element that followed it.
Undefined behavior if 'elem' is not in a list. */
static inline struct ovs_list *
list_remove(struct ovs_list *elem)
ovs_list_remove(struct ovs_list *elem)
{
elem->prev->next = elem->next;
elem->next->prev = elem->prev;
Expand All @@ -213,53 +213,53 @@ list_remove(struct ovs_list *elem)
/* Removes the front element from 'list' and returns it. Undefined behavior if
'list' is empty before removal. */
static inline struct ovs_list *
list_pop_front(struct ovs_list *list)
ovs_list_pop_front(struct ovs_list *list)
{
struct ovs_list *front = list->next;

list_remove(front);
ovs_list_remove(front);
return front;
}

/* Removes the back element from 'list' and returns it.
Undefined behavior if 'list' is empty before removal. */
static inline struct ovs_list *
list_pop_back(struct ovs_list *list)
ovs_list_pop_back(struct ovs_list *list)
{
struct ovs_list *back = list->prev;

list_remove(back);
ovs_list_remove(back);
return back;
}

/* Returns the front element in 'list_'.
Undefined behavior if 'list_' is empty. */
static inline struct ovs_list *
list_front(const struct ovs_list *list_)
ovs_list_front(const struct ovs_list *list_)
{
struct ovs_list *list = CONST_CAST(struct ovs_list *, list_);

ovs_assert(!list_is_empty(list));
ovs_assert(!ovs_list_is_empty(list));

return list->next;
}

/* Returns the back element in 'list_'.
Undefined behavior if 'list_' is empty. */
static inline struct ovs_list *
list_back(const struct ovs_list *list_)
ovs_list_back(const struct ovs_list *list_)
{
struct ovs_list *list = CONST_CAST(struct ovs_list *, list_);

ovs_assert(!list_is_empty(list));
ovs_assert(!ovs_list_is_empty(list));

return list->prev;
}

/* Returns the number of elements in 'list'.
Runs in O(n) in the number of elements. */
static inline size_t
list_size(const struct ovs_list *list)
ovs_list_size(const struct ovs_list *list)
{
const struct ovs_list *e;
size_t cnt = 0;
Expand All @@ -272,21 +272,21 @@ list_size(const struct ovs_list *list)

/* Returns true if 'list' is empty, false otherwise. */
static inline bool
list_is_empty(const struct ovs_list *list)
ovs_list_is_empty(const struct ovs_list *list)
{
return list->next == list;
}

/* Returns true if 'list' has exactly 1 element, false otherwise. */
static inline bool
list_is_singleton(const struct ovs_list *list)
ovs_list_is_singleton(const struct ovs_list *list)
{
return list_is_short(list) && !list_is_empty(list);
return ovs_list_is_short(list) && !ovs_list_is_empty(list);
}

/* Returns true if 'list' has 0 or 1 elements, false otherwise. */
static inline bool
list_is_short(const struct ovs_list *list)
ovs_list_is_short(const struct ovs_list *list)
{
return list->next == list->prev;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/dpif-netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -2864,7 +2864,7 @@ dp_netdev_configure_pmd(struct dp_netdev_pmd_thread *pmd, struct dp_netdev *dp,
ovs_mutex_init(&pmd->poll_mutex);
dpcls_init(&pmd->cls);
cmap_init(&pmd->flow_table);
list_init(&pmd->poll_list);
ovs_list_init(&pmd->poll_list);
/* init the 'flow_cache' since there is no
* actual thread created for NON_PMD_CORE_ID. */
if (core_id == NON_PMD_CORE_ID) {
Expand Down Expand Up @@ -3017,7 +3017,7 @@ dp_netdev_del_port_from_pmd(struct dp_netdev_port *port,
if (poll->port == port) {
found = true;
port_unref(poll->port);
list_remove(&poll->node);
ovs_list_remove(&poll->node);
pmd->poll_cnt--;
free(poll);
}
Expand Down Expand Up @@ -3076,7 +3076,7 @@ dp_netdev_add_rxq_to_pmd(struct dp_netdev_pmd_thread *pmd,
poll->port = port;
poll->rx = rx;

list_push_back(&pmd->poll_list, &poll->node);
ovs_list_push_back(&pmd->poll_list, &poll->node);
pmd->poll_cnt++;
}

Expand Down
8 changes: 4 additions & 4 deletions lib/fat-rwlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ free_slot(struct fat_rwlock_slot *slot)
abort();
}

list_remove(&slot->list_node);
ovs_list_remove(&slot->list_node);
free_cacheline(slot);
}

Expand All @@ -88,7 +88,7 @@ fat_rwlock_init(struct fat_rwlock *rwlock)
ovsthread_key_create(&rwlock->key, slot_destructor);
ovs_mutex_init(&rwlock->mutex);
ovs_mutex_lock(&rwlock->mutex);
list_init(&rwlock->threads);
ovs_list_init(&rwlock->threads);
ovs_mutex_unlock(&rwlock->mutex);
}

Expand Down Expand Up @@ -129,7 +129,7 @@ fat_rwlock_get_slot__(struct fat_rwlock *rwlock)
slot->depth = 0;

ovs_mutex_lock(&rwlock->mutex);
list_push_back(&rwlock->threads, &slot->list_node);
ovs_list_push_back(&rwlock->threads, &slot->list_node);
ovs_mutex_unlock(&rwlock->mutex);

ovsthread_setspecific(rwlock->key, slot);
Expand Down Expand Up @@ -181,7 +181,7 @@ fat_rwlock_try_get_slot__(struct fat_rwlock *rwlock)
ovs_mutex_init(&slot->mutex);
slot->depth = 0;

list_push_back(&rwlock->threads, &slot->list_node);
ovs_list_push_back(&rwlock->threads, &slot->list_node);
ovs_mutex_unlock(&rwlock->mutex);
ovsthread_setspecific(rwlock->key, slot);
}
Expand Down
10 changes: 5 additions & 5 deletions lib/guarded-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void
guarded_list_init(struct guarded_list *list)
{
ovs_mutex_init(&list->mutex);
list_init(&list->list);
ovs_list_init(&list->list);
list->n = 0;
}

Expand Down Expand Up @@ -57,7 +57,7 @@ guarded_list_push_back(struct guarded_list *list,

ovs_mutex_lock(&list->mutex);
if (list->n < max) {
list_push_back(&list->list, node);
ovs_list_push_back(&list->list, node);
retval = ++list->n;
}
ovs_mutex_unlock(&list->mutex);
Expand All @@ -72,7 +72,7 @@ guarded_list_pop_front(struct guarded_list *list)

ovs_mutex_lock(&list->mutex);
if (list->n) {
node = list_pop_front(&list->list);
node = ovs_list_pop_front(&list->list);
list->n--;
}
ovs_mutex_unlock(&list->mutex);
Expand All @@ -86,10 +86,10 @@ guarded_list_pop_all(struct guarded_list *list, struct ovs_list *elements)
size_t n;

ovs_mutex_lock(&list->mutex);
list_move(elements, &list->list);
ovs_list_move(elements, &list->list);
n = list->n;

list_init(&list->list);
ovs_list_init(&list->list);
list->n = 0;
ovs_mutex_unlock(&list->mutex);

Expand Down
Loading

0 comments on commit 417e7e6

Please sign in to comment.