[ovs-dev] [groups v2 1/2] list: New function list_move().
Ben Pfaff
blp at nicira.com
Thu Aug 29 06:55:36 UTC 2013
An upcoming commit will add more users.
Signed-off-by: Ben Pfaff <blp at nicira.com>
---
lib/list.c | 14 ++++++++++++++
lib/list.h | 3 ++-
ofproto/ofproto-dpif.c | 22 ++++++----------------
3 files changed, 22 insertions(+), 17 deletions(-)
diff --git a/lib/list.c b/lib/list.c
index 227546e..e341d45 100644
--- a/lib/list.c
+++ b/lib/list.c
@@ -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 *
diff --git a/lib/list.h b/lib/list.h
index 786b176..0da082e 100644
--- a/lib/list.h
+++ b/lib/list.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2009, 2010, 2011 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2011, 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.
@@ -40,6 +40,7 @@ void list_push_front(struct list *, struct list *);
void list_push_back(struct list *, struct list *);
void list_replace(struct list *, const struct list *);
void list_moved(struct list *);
+void list_move(struct list *dst, struct list *src);
/* List removal. */
struct list *list_remove(struct list *);
diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
index d4c8f73..820ec34 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -1500,14 +1500,9 @@ run_fast(struct ofproto *ofproto_)
}
ovs_mutex_lock(&ofproto->flow_mod_mutex);
- if (ofproto->n_flow_mods) {
- flow_mods = ofproto->flow_mods;
- list_moved(&flow_mods);
- list_init(&ofproto->flow_mods);
- ofproto->n_flow_mods = 0;
- } else {
- list_init(&flow_mods);
- }
+ list_move(&flow_mods, &ofproto->flow_mods);
+ list_init(&ofproto->flow_mods);
+ ofproto->n_flow_mods = 0;
ovs_mutex_unlock(&ofproto->flow_mod_mutex);
LIST_FOR_EACH_SAFE (fm, next_fm, list_node, &flow_mods) {
@@ -1523,14 +1518,9 @@ run_fast(struct ofproto *ofproto_)
}
ovs_mutex_lock(&ofproto->pin_mutex);
- if (ofproto->n_pins) {
- pins = ofproto->pins;
- list_moved(&pins);
- list_init(&ofproto->pins);
- ofproto->n_pins = 0;
- } else {
- list_init(&pins);
- }
+ list_move(&pins, &ofproto->pins);
+ list_init(&ofproto->pins);
+ ofproto->n_pins = 0;
ovs_mutex_unlock(&ofproto->pin_mutex);
LIST_FOR_EACH_SAFE (pin, next_pin, list_node, &pins) {
--
1.7.10.4
More information about the dev
mailing list