Skip to content

Commit

Permalink
ovs-atomic: Delete atomic, atomic_flag, ovs_refcount destroy functions.
Browse files Browse the repository at this point in the history
None of the atomic implementations need a destroy function anymore, so it's
"more standard" and more convenient for users to get rid of them.

Signed-off-by: Ben Pfaff <[email protected]>
Acked-by: Andy Zhou <[email protected]>
  • Loading branch information
blp committed Mar 13, 2014
1 parent 6a36690 commit 8917f72
Show file tree
Hide file tree
Showing 23 changed files with 12 additions and 120 deletions.
3 changes: 1 addition & 2 deletions lib/bfd.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2013 Nicira, Inc.
/* Copyright (c) 2013, 2014 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -469,7 +469,6 @@ bfd_unref(struct bfd *bfd) OVS_EXCLUDED(mutex)
ovs_mutex_lock(&mutex);
hmap_remove(all_bfds, &bfd->node);
netdev_close(bfd->netdev);
ovs_refcount_destroy(&bfd->ref_cnt);
free(bfd->name);
free(bfd);
ovs_mutex_unlock(&mutex);
Expand Down
6 changes: 1 addition & 5 deletions lib/cfm.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2011, 2012, 2013 Nicira, Inc.
* Copyright (c) 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -372,10 +372,6 @@ cfm_unref(struct cfm *cfm) OVS_EXCLUDED(mutex)
netdev_close(cfm->netdev);
free(cfm->rmps_array);

atomic_destroy(&cfm->extended);
atomic_destroy(&cfm->check_tnl_key);
ovs_refcount_destroy(&cfm->ref_cnt);

free(cfm);
}

Expand Down
3 changes: 1 addition & 2 deletions lib/dpif-linux.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -1120,7 +1120,6 @@ dpif_linux_flow_dump_done(const struct dpif *dpif OVS_UNUSED, void *iter_)
unsigned int nl_status = nl_dump_done(&iter->dump);

atomic_read(&iter->status, &dump_status);
atomic_destroy(&iter->status);
free(iter);
return dump_status ? dump_status : nl_status;
}
Expand Down
5 changes: 0 additions & 5 deletions lib/dpif-netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,6 @@ create_dp_netdev(const char *name, const struct dpif_class *class,
*CONST_CAST(const struct dpif_class **, &dp->class) = class;
*CONST_CAST(const char **, &dp->name) = xstrdup(name);
ovs_refcount_init(&dp->ref_cnt);
atomic_flag_init(&dp->destroyed);

ovs_mutex_init(&dp->flow_mutex);
classifier_init(&dp->cls, NULL);
Expand Down Expand Up @@ -558,8 +557,6 @@ dp_netdev_free(struct dp_netdev *dp)
ovs_mutex_destroy(&dp->flow_mutex);
seq_destroy(dp->port_seq);
hmap_destroy(&dp->ports);
atomic_flag_destroy(&dp->destroyed);
ovs_refcount_destroy(&dp->ref_cnt);
latch_destroy(&dp->exit_latch);
free(CONST_CAST(char *, dp->name));
free(dp);
Expand Down Expand Up @@ -871,7 +868,6 @@ dp_netdev_flow_unref(struct dp_netdev_flow *flow)
cls_rule_destroy(CONST_CAST(struct cls_rule *, &flow->cr));
ovs_mutex_lock(&flow->mutex);
dp_netdev_actions_unref(flow->actions);
ovs_refcount_destroy(&flow->ref_cnt);
ovs_mutex_unlock(&flow->mutex);
ovs_mutex_destroy(&flow->mutex);
free(flow);
Expand Down Expand Up @@ -1579,7 +1575,6 @@ void
dp_netdev_actions_unref(struct dp_netdev_actions *actions)
{
if (actions && ovs_refcount_unref(&actions->ref_cnt) == 1) {
ovs_refcount_destroy(&actions->ref_cnt);
free(actions->actions);
free(actions);
}
Expand Down
3 changes: 1 addition & 2 deletions lib/lacp.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2011, 2012, 2013 Nicira, Inc.
/* Copyright (c) 2011, 2012, 2013, 2014 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -249,7 +249,6 @@ lacp_unref(struct lacp *lacp) OVS_EXCLUDED(mutex)
hmap_destroy(&lacp->slaves);
list_remove(&lacp->node);
free(lacp->name);
ovs_refcount_destroy(&lacp->ref_cnt);
free(lacp);
ovs_mutex_unlock(&mutex);
}
Expand Down
3 changes: 1 addition & 2 deletions lib/mac-learning.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -141,7 +141,6 @@ mac_learning_unref(struct mac_learning *ml)

bitmap_free(ml->flood_vlans);
ovs_rwlock_destroy(&ml->rwlock);
ovs_refcount_destroy(&ml->ref_cnt);
free(ml);
}
}
Expand Down
1 change: 0 additions & 1 deletion lib/netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ netdev_unregister_provider(const char *type)
atomic_read(&rc->ref_cnt, &ref_cnt);
if (!ref_cnt) {
hmap_remove(&netdev_classes, &rc->hmap_node);
atomic_destroy(&rc->ref_cnt);
free(rc);
error = 0;
} else {
Expand Down
1 change: 0 additions & 1 deletion lib/netlink-socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,6 @@ nl_dump_done(struct nl_dump *dump)
ovs_assert(status);
ofpbuf_uninit(&buf);
}
atomic_destroy(&dump->status);
nl_pool_release(dump->sock);
seq_destroy(dump->status_seq);
return status >> 1;
Expand Down
12 changes: 0 additions & 12 deletions lib/ovs-atomic-c11.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,3 @@
(*(ORIG) = atomic_fetch_xor_explicit(RMW, ARG, ORDER), (void) 0)
#define atomic_and_explicit(RMW, ARG, ORIG, ORDER) \
(*(ORIG) = atomic_fetch_and_explicit(RMW, ARG, ORDER), (void) 0)

static inline void
atomic_flag_init(volatile atomic_flag *object OVS_UNUSED)
{
/* Nothing to do. */
}

static inline void
atomic_flag_destroy(volatile atomic_flag *object OVS_UNUSED)
{
/* Nothing to do. */
}
1 change: 0 additions & 1 deletion lib/ovs-atomic-clang.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#define ATOMIC_VAR_INIT(VALUE) (VALUE)

#define atomic_init(OBJECT, VALUE) __c11_atomic_init(OBJECT, VALUE)
#define atomic_destroy(OBJECT) ((void) (OBJECT))

/* Clang hard-codes these exact values internally but does not appear to
* export any names for them. */
Expand Down
14 changes: 1 addition & 13 deletions lib/ovs-atomic-flag-gcc4.7+.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013 Nicira, Inc.
* Copyright (c) 2013, 2014 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,18 +26,6 @@ typedef struct {
} atomic_flag;
#define ATOMIC_FLAG_INIT { .b = false }

static inline void
atomic_flag_init(volatile atomic_flag *object OVS_UNUSED)
{
/* Nothing to do. */
}

static inline void
atomic_flag_destroy(volatile atomic_flag *object OVS_UNUSED)
{
/* Nothing to do. */
}

static inline bool
atomic_flag_test_and_set_explicit(volatile atomic_flag *object,
memory_order order)
Expand Down
13 changes: 0 additions & 13 deletions lib/ovs-atomic-gcc4+.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ typedef enum {

#define ATOMIC_VAR_INIT(VALUE) VALUE
#define atomic_init(OBJECT, VALUE) (*(OBJECT) = (VALUE), (void) 0)
#define atomic_destroy(OBJECT) ((void) (OBJECT))

static inline void
atomic_thread_fence(memory_order order)
Expand Down Expand Up @@ -146,18 +145,6 @@ typedef struct {
} atomic_flag;
#define ATOMIC_FLAG_INIT { false }

static inline void
atomic_flag_init(volatile atomic_flag *object OVS_UNUSED)
{
/* Nothing to do. */
}

static inline void
atomic_flag_destroy(volatile atomic_flag *object OVS_UNUSED)
{
/* Nothing to do. */
}

static inline bool
atomic_flag_test_and_set(volatile atomic_flag *object)
{
Expand Down
1 change: 0 additions & 1 deletion lib/ovs-atomic-gcc4.7+.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ typedef enum {

#define ATOMIC_VAR_INIT(VALUE) (VALUE)
#define atomic_init(OBJECT, VALUE) (*(OBJECT) = (VALUE), (void) 0)
#define atomic_destroy(OBJECT) ((void) (OBJECT))

#define atomic_thread_fence __atomic_thread_fence
#define atomic_signal_fence __atomic_signal_fence
Expand Down
13 changes: 0 additions & 13 deletions lib/ovs-atomic-pthreads.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ typedef enum {

#define ATOMIC_VAR_INIT(VALUE) (VALUE)
#define atomic_init(OBJECT, VALUE) (*(OBJECT) = (VALUE), (void) 0)
#define atomic_destroy(OBJECT) ((void) (OBJECT))

static inline void
atomic_thread_fence(memory_order order OVS_UNUSED)
Expand Down Expand Up @@ -92,18 +91,6 @@ typedef struct {
} atomic_flag;
#define ATOMIC_FLAG_INIT { false }

static inline void
atomic_flag_init(volatile atomic_flag *flag OVS_UNUSED)
{
/* Nothing to do. */
}

static inline void
atomic_flag_destroy(volatile atomic_flag *flag OVS_UNUSED)
{
/* Nothing to do. */
}

static inline bool
atomic_flag_test_and_set(volatile atomic_flag *flag_)
{
Expand Down
30 changes: 1 addition & 29 deletions lib/ovs-atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,6 @@
* ...
* atomic_init(&ai, 123);
*
* C11 does not hav an destruction function for atomic types, but some
* implementations of the OVS atomics do need them. Thus, the following
* function is provided for destroying non-static atomic objects (A is any
* atomic type):
*
* void atomic_destroy(A *object);
*
* Destroys 'object'.
*
*
* Barriers
* ========
Expand Down Expand Up @@ -224,19 +215,7 @@
* ATOMIC_FLAG_INIT is an initializer for atomic_flag. The initial state is
* "clear".
*
* C11 does not have an initialization or destruction function for atomic_flag,
* because implementations should not need one (one may simply
* atomic_flag_clear() an uninitialized atomic_flag), but some implementations
* of the OVS atomics do need them. Thus, the following two functions are
* provided for initializing and destroying non-static atomic_flags:
*
* void atomic_flag_init(volatile atomic_flag *object);
*
* Initializes 'object'. The initial state is "clear".
*
* void atomic_flag_destroy(volatile atomic_flag *object);
*
* Destroys 'object'.
* An atomic_flag may also be initialized at runtime with atomic_flag_clear().
*
*
* Operations
Expand Down Expand Up @@ -336,13 +315,6 @@ ovs_refcount_init(struct ovs_refcount *refcount)
atomic_init(&refcount->count, 1);
}

/* Destroys 'refcount'. */
static inline void
ovs_refcount_destroy(struct ovs_refcount *refcount)
{
atomic_destroy(&refcount->count);
}

/* Increments 'refcount'. */
static inline void
ovs_refcount_ref(struct ovs_refcount *refcount)
Expand Down
3 changes: 1 addition & 2 deletions lib/stp.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -332,7 +332,6 @@ stp_unref(struct stp *stp)
list_remove(&stp->node);
ovs_mutex_unlock(&mutex);
free(stp->name);
ovs_refcount_destroy(&stp->ref_cnt);
free(stp);
}
}
Expand Down
3 changes: 1 addition & 2 deletions ofproto/bond.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -236,7 +236,6 @@ bond_unref(struct bond *bond)
ovs_mutex_destroy(&bond->mutex);
free(bond->hash);
free(bond->name);
ovs_refcount_destroy(&bond->ref_cnt);
free(bond);
}

Expand Down
3 changes: 1 addition & 2 deletions ofproto/netflow.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2013 Nicira, Inc.
* Copyright (c) 2008, 2009, 2010, 2011, 2013, 2014 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -430,7 +430,6 @@ netflow_unref(struct netflow *nf)
atomic_sub(&netflow_count, 1, &orig);
collectors_destroy(nf->collectors);
ofpbuf_uninit(&nf->packet);
ovs_refcount_destroy(&nf->ref_cnt);
free(nf);
}
}
Expand Down
3 changes: 1 addition & 2 deletions ofproto/ofproto-dpif-ipfix.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2013 Nicira, Inc.
* Copyright (c) 2012, 2013, 2014 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -699,7 +699,6 @@ dpif_ipfix_unref(struct dpif_ipfix *di) OVS_EXCLUDED(mutex)
dpif_ipfix_clear(di);
dpif_ipfix_bridge_exporter_destroy(&di->bridge_exporter);
hmap_destroy(&di->flow_exporter_map);
ovs_refcount_destroy(&di->ref_cnt);
free(di);
ovs_mutex_unlock(&mutex);
}
Expand Down
1 change: 0 additions & 1 deletion ofproto/ofproto-dpif-sflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,6 @@ dpif_sflow_unref(struct dpif_sflow *ds) OVS_EXCLUDED(mutex)
dpif_sflow_del_port__(ds, dsp);
}
hmap_destroy(&ds->ports);
ovs_refcount_destroy(&ds->ref_cnt);
free(ds);
}
}
Expand Down
3 changes: 0 additions & 3 deletions ofproto/ofproto-dpif-upcall.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,6 @@ udpif_destroy(struct udpif *udpif)
latch_destroy(&udpif->exit_latch);
seq_destroy(udpif->reval_seq);
seq_destroy(udpif->dump_seq);
atomic_destroy(&udpif->flow_limit);
atomic_destroy(&udpif->n_flows);
atomic_destroy(&udpif->n_flows_timestamp);
ovs_mutex_destroy(&udpif->n_flows_mutex);
free(udpif);
}
Expand Down
3 changes: 0 additions & 3 deletions ofproto/ofproto.c
Original file line number Diff line number Diff line change
Expand Up @@ -2615,7 +2615,6 @@ ofproto_rule_destroy__(struct rule *rule)
cls_rule_destroy(CONST_CAST(struct cls_rule *, &rule->cr));
rule_actions_unref(rule->actions);
ovs_mutex_destroy(&rule->mutex);
ovs_refcount_destroy(&rule->ref_count);
rule->ofproto->ofproto_class->rule_dealloc(rule);
}

Expand Down Expand Up @@ -2656,7 +2655,6 @@ void
rule_actions_unref(struct rule_actions *actions)
{
if (actions && ovs_refcount_unref(&actions->ref_count) == 1) {
ovs_refcount_destroy(&actions->ref_count);
free(actions->ofpacts);
free(actions);
}
Expand Down Expand Up @@ -6705,7 +6703,6 @@ oftable_destroy(struct oftable *table)
oftable_disable_eviction(table);
classifier_destroy(&table->cls);
free(table->name);
atomic_destroy(&table->config);
}

/* Changes the name of 'table' to 'name'. If 'name' is NULL or the empty
Expand Down
Loading

0 comments on commit 8917f72

Please sign in to comment.