diff options
author | Ben Pfaff <blp@ovn.org> | 2016-04-22 16:51:03 -0700 |
---|---|---|
committer | Ben Pfaff <blp@ovn.org> | 2016-05-09 16:42:56 -0700 |
commit | b70e697679bd0b8f248348be6985c996f85643ab (patch) | |
tree | bdafe95e3058fd0181f9c42910a6be500d0e3884 /ofproto/ofproto-dpif-rid.c | |
parent | 790c5d2694bb3ddc3927b2e3617157ba2b19dc39 (diff) | |
download | openvswitch-b70e697679bd0b8f248348be6985c996f85643ab.tar.gz |
cmap: New macro CMAP_INITIALIZER, for initializing an empty cmap.
Sometimes code is much simpler if we can statically initialize data
structures. Until now, this has not been possible for cmap-based data
structures, so this commit introduces a CMAP_INITIALIZER macro.
This works by adding a singleton empty cmap_impl that simply forces the
first insertion into any cmap that points to it to allocate a real
cmap_impl. There could be some risk that rogue code modifies the
singleton, so for safety it is also marked 'const' to allow the linker to
put it into a read-only page.
This adds a new OVS_ALIGNED_VAR macro with GCC and MSVC implementations.
The latter is based on Microsoft webpages, so developers who know Windows
might want to scrutinize it.
As examples of the kind of simplification this can make possible, this
commit removes an initialization function from ofproto-dpif-rid.c and a
call to cmap_init() from tnl-neigh-cache.c. An upcoming commit will add
another user.
CC: Jarno Rajahalme <jarno@ovn.org>
CC: Gurucharan Shetty <guru@ovn.org>
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Ryan Moats <rmoats@us.ibm.com>
Diffstat (limited to 'ofproto/ofproto-dpif-rid.c')
-rw-r--r-- | ofproto/ofproto-dpif-rid.c | 34 |
1 files changed, 8 insertions, 26 deletions
diff --git a/ofproto/ofproto-dpif-rid.c b/ofproto/ofproto-dpif-rid.c index b3f64f99e..f59775cc5 100644 --- a/ofproto/ofproto-dpif-rid.c +++ b/ofproto/ofproto-dpif-rid.c @@ -24,40 +24,22 @@ VLOG_DEFINE_THIS_MODULE(ofproto_dpif_rid); -static struct ovs_mutex mutex; +static struct ovs_mutex mutex = OVS_MUTEX_INITIALIZER; -static struct cmap id_map; -static struct cmap metadata_map; +static struct cmap id_map = CMAP_INITIALIZER; +static struct cmap metadata_map = CMAP_INITIALIZER; -static struct ovs_list expiring OVS_GUARDED_BY(mutex); -static struct ovs_list expired OVS_GUARDED_BY(mutex); +static struct ovs_list expiring OVS_GUARDED_BY(mutex) + = OVS_LIST_INITIALIZER(&expiring); +static struct ovs_list expired OVS_GUARDED_BY(mutex) + = OVS_LIST_INITIALIZER(&expired); -static uint32_t next_id OVS_GUARDED_BY(mutex); /* Possible next free id. */ +static uint32_t next_id OVS_GUARDED_BY(mutex) = 1; /* Possible next free id. */ #define RECIRC_POOL_STATIC_IDS 1024 static void recirc_id_node_free(struct recirc_id_node *); -void -recirc_init(void) -{ - static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER; - - if (ovsthread_once_start(&once)) { - ovs_mutex_init(&mutex); - ovs_mutex_lock(&mutex); - next_id = 1; /* 0 is not a valid ID. */ - cmap_init(&id_map); - cmap_init(&metadata_map); - ovs_list_init(&expiring); - ovs_list_init(&expired); - ovs_mutex_unlock(&mutex); - - ovsthread_once_done(&once); - } - -} - /* This should be called by the revalidator once at each round (every 500ms or * more). */ void |