Replace all uses of strerror() by ovs_strerror(), for thread safety.
[sliver-openvswitch.git] / ofproto / ofproto-dpif-sflow.c
index ee31f88..64e6c96 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc.
+ * Copyright (c) 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
  * Copyright (c) 2009 InMon Corp.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -57,6 +57,7 @@ struct dpif_sflow {
     size_t n_flood, n_all;
     struct hmap ports;          /* Contains "struct dpif_sflow_port"s. */
     uint32_t probability;
+    int ref_cnt;
 };
 
 static void dpif_sflow_del_port__(struct dpif_sflow *,
@@ -302,10 +303,22 @@ dpif_sflow_create(void)
     hmap_init(&ds->ports);
     ds->probability = 0;
     route_table_register();
+    ds->ref_cnt = 1;
 
     return ds;
 }
 
+struct dpif_sflow *
+dpif_sflow_ref(const struct dpif_sflow *ds_)
+{
+    struct dpif_sflow *ds = CONST_CAST(struct dpif_sflow *, ds_);
+    if (ds) {
+        ovs_assert(ds->ref_cnt > 0);
+        ds->ref_cnt++;
+    }
+    return ds;
+}
+
 /* 32-bit fraction of packets to sample with.  A value of 0 samples no packets,
  * a value of %UINT32_MAX samples all packets and intermediate values sample
  * intermediate fractions of packets. */
@@ -316,9 +329,14 @@ dpif_sflow_get_probability(const struct dpif_sflow *ds)
 }
 
 void
-dpif_sflow_destroy(struct dpif_sflow *ds)
+dpif_sflow_unref(struct dpif_sflow *ds)
 {
-    if (ds) {
+    if (!ds) {
+        return;
+    }
+
+    ovs_assert(ds->ref_cnt > 0);
+    if (!--ds->ref_cnt) {
         struct dpif_sflow_port *dsp, *next;
 
         route_table_unregister();