cmap: New macro CMAP_INITIALIZER, for initializing an empty cmap.
authorBen Pfaff <blp@ovn.org>
Fri, 22 Apr 2016 23:51:03 +0000 (16:51 -0700)
committerBen Pfaff <blp@ovn.org>
Mon, 9 May 2016 23:42:56 +0000 (16:42 -0700)
commitb70e697679bd0b8f248348be6985c996f85643ab
treebdafe95e3058fd0181f9c42910a6be500d0e3884
parent790c5d2694bb3ddc3927b2e3617157ba2b19dc39
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>
include/openvswitch/compiler.h
lib/cmap.c
lib/cmap.h
lib/tnl-neigh-cache.c
ofproto/ofproto-dpif-rid.c
ofproto/ofproto-dpif-rid.h
ofproto/ofproto-dpif.c
tests/test-cmap.c