[ovs-dev] [race-fix 2/6] classifier: New function cls_rule_move().

Ben Pfaff blp at nicira.com
Tue Aug 27 00:10:01 UTC 2013


This function will acquire its first user in an upcoming commit.

Signed-off-by: Ben Pfaff <blp at nicira.com>
---
 lib/classifier.c |   12 +++++++++++-
 lib/classifier.h |    3 ++-
 lib/flow.c       |   23 +++++++++++++++++++++++
 lib/flow.h       |    2 ++
 lib/match.c      |    9 +++++++++
 lib/match.h      |    3 ++-
 6 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/lib/classifier.c b/lib/classifier.c
index 556278f..efd562a 100644
--- a/lib/classifier.c
+++ b/lib/classifier.c
@@ -89,7 +89,7 @@ cls_rule_init_from_minimatch(struct cls_rule *rule,
 
 /* Initializes 'dst' as a copy of 'src'.
  *
- * The caller must eventually destroy 'rule' with cls_rule_destroy(). */
+ * The caller must eventually destroy 'dst' with cls_rule_destroy(). */
 void
 cls_rule_clone(struct cls_rule *dst, const struct cls_rule *src)
 {
@@ -97,6 +97,16 @@ cls_rule_clone(struct cls_rule *dst, const struct cls_rule *src)
     dst->priority = src->priority;
 }
 
+/* Replaces 'dst' by 'src', destroying 'src'.
+ *
+ * The caller must eventually destroy 'dst' with cls_rule_destroy(). */
+void
+cls_rule_move(struct cls_rule *dst, struct cls_rule *src)
+{
+    minimatch_move(&dst->match, &src->match);
+    dst->priority = src->priority;
+}
+
 /* Frees memory referenced by 'rule'.  Doesn't free 'rule' itself (it's
  * normally embedded into a larger structure).
  *
diff --git a/lib/classifier.h b/lib/classifier.h
index 3f89196..5a45458 100644
--- a/lib/classifier.h
+++ b/lib/classifier.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc.
+ * Copyright (c) 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.
@@ -86,6 +86,7 @@ void cls_rule_init(struct cls_rule *, const struct match *,
 void cls_rule_init_from_minimatch(struct cls_rule *, const struct minimatch *,
                                   unsigned int priority);
 void cls_rule_clone(struct cls_rule *, const struct cls_rule *);
+void cls_rule_move(struct cls_rule *dst, struct cls_rule *src);
 void cls_rule_destroy(struct cls_rule *);
 
 bool cls_rule_equal(const struct cls_rule *, const struct cls_rule *);
diff --git a/lib/flow.c b/lib/flow.c
index ab49b80..07dcbd1 100644
--- a/lib/flow.c
+++ b/lib/flow.c
@@ -1136,6 +1136,21 @@ miniflow_clone(struct miniflow *dst, const struct miniflow *src)
     memcpy(dst->values, src->values, n * sizeof *dst->values);
 }
 
+/* Replaces 'dst' by 'src', destroying 'src'.  The caller must eventually free
+ * 'dst' with miniflow_destroy(). */
+void
+miniflow_move(struct miniflow *dst, struct miniflow *src)
+{
+    int n = miniflow_n_values(src);
+    if (n <= MINI_N_INLINE) {
+        dst->values = dst->inline_values;
+        memcpy(dst->values, src->values, n * sizeof *dst->values);
+    } else {
+        dst->values = src->values;
+    }
+    memcpy(dst->map, src->map, sizeof dst->map);
+}
+
 /* Frees any memory owned by 'flow'.  Does not free the storage in which 'flow'
  * itself resides; the caller is responsible for that. */
 void
@@ -1353,6 +1368,14 @@ minimask_clone(struct minimask *dst, const struct minimask *src)
     miniflow_clone(&dst->masks, &src->masks);
 }
 
+/* Replaces 'dst' by 'src', destroying 'src'.  The caller must eventually free
+ * 'dst' with minimask_destroy(). */
+void
+minimask_move(struct minimask *dst, struct minimask *src)
+{
+    miniflow_clone(&dst->masks, &src->masks);
+}
+
 /* Initializes 'dst_' as the bit-wise "and" of 'a_' and 'b_'.
  *
  * The caller must provide room for FLOW_U32S "uint32_t"s in 'storage', for use
diff --git a/lib/flow.h b/lib/flow.h
index ecd850a..75d95e8 100644
--- a/lib/flow.h
+++ b/lib/flow.h
@@ -321,6 +321,7 @@ struct miniflow {
 
 void miniflow_init(struct miniflow *, const struct flow *);
 void miniflow_clone(struct miniflow *, const struct miniflow *);
+void miniflow_move(struct miniflow *dst, struct miniflow *);
 void miniflow_destroy(struct miniflow *);
 
 void miniflow_expand(const struct miniflow *, struct flow *);
@@ -350,6 +351,7 @@ struct minimask {
 
 void minimask_init(struct minimask *, const struct flow_wildcards *);
 void minimask_clone(struct minimask *, const struct minimask *);
+void minimask_move(struct minimask *dst, struct minimask *src);
 void minimask_combine(struct minimask *dst,
                       const struct minimask *a, const struct minimask *b,
                       uint32_t storage[FLOW_U32S]);
diff --git a/lib/match.c b/lib/match.c
index c038d48..9be7bab 100644
--- a/lib/match.c
+++ b/lib/match.c
@@ -1104,6 +1104,15 @@ minimatch_clone(struct minimatch *dst, const struct minimatch *src)
     minimask_clone(&dst->mask, &src->mask);
 }
 
+/* Replaces 'dst' by 'src', destroying 'src'.  The caller must eventually free
+ * 'dst' with minimatch_destroy(). */
+void
+minimatch_move(struct minimatch *dst, struct minimatch *src)
+{
+    miniflow_move(&dst->flow, &src->flow);
+    minimask_move(&dst->mask, &src->mask);
+}
+
 /* Frees any memory owned by 'match'.  Does not free the storage in which
  * 'match' itself resides; the caller is responsible for that. */
 void
diff --git a/lib/match.h b/lib/match.h
index 5788721..7b104ee 100644
--- a/lib/match.h
+++ b/lib/match.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc.
+ * Copyright (c) 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.
@@ -146,6 +146,7 @@ struct minimatch {
 
 void minimatch_init(struct minimatch *, const struct match *);
 void minimatch_clone(struct minimatch *, const struct minimatch *);
+void minimatch_move(struct minimatch *dst, struct minimatch *src);
 void minimatch_destroy(struct minimatch *);
 
 void minimatch_expand(const struct minimatch *, struct match *);
-- 
1.7.10.4




More information about the dev mailing list