From: Ben Pfaff Date: Thu, 29 Aug 2013 20:06:21 +0000 (-0700) Subject: list: New function list_move(). X-Git-Tag: v2.0~57 X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Fovs.git;a=commitdiff_plain;h=701387bf406520af1b13ef79e3bde4547983f3f7 list: New function list_move(). An upcoming commit will add more users. Signed-off-by: Ben Pfaff Reviewed-by: Simon Horman --- diff --git a/lib/list.c b/lib/list.c index 227546e95..e341d45bd 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 786b176c1..0da082e51 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 03d5c1fe4..7bfdad913 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -1533,14 +1533,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) { @@ -1556,14 +1551,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) {