ovs-atomic: Use raw types, not structs, when locks are required.
authorBen Pfaff <blp@nicira.com>
Tue, 11 Mar 2014 19:46:29 +0000 (12:46 -0700)
committerBen Pfaff <blp@nicira.com>
Thu, 13 Mar 2014 19:45:22 +0000 (12:45 -0700)
commit1bd2c9edc3455a73e92dbeac7dce8f7754d4b39f
tree3c6ba0da86f4cd310f8fc93dce88145ffc548a08
parent7d53f6b0228e40b9c1ebef83ce8273a8f0103520
ovs-atomic: Use raw types, not structs, when locks are required.

Until now, the GCC 4+ and pthreads implementations of atomics have used
struct wrappers for their atomic types.  This had the advantage of allowing
a mutex to be wrapped in, in some cases, and of better type-checking by
preventing stray uses of atomic variables other than through one of the
atomic_*() functions or macros.  However, the mutex meant that an
atomic_destroy() function-like macro needed to be used.  The struct wrapper
also made it impossible to define new atomic types that were compatible
with each other without using a typedef.  For example, one could not simply
define a macro like
    #define ATOMIC(TYPE) struct { TYPE value; }
and then have two declarations like:
    ATOMIC(void *) x;
    ATOMIC(void *) y;
and do anything with these objects that require type-compatibility, even
"&x == &y", because the two structs are not compatible.  One can do it
through a typedef:
    typedef ATOMIC(void *) atomic_voidp;
    atomic_voidp x, y;
but that is inconvenient, especially because of the need to invent a name
for the type.

This commit aims to ease the problem by getting rid of the wrapper structs
in the cases where the atomic library used them.  It gets rid of the
mutexes, in the cases where they are still needed, by using a global
array of mutexes instead.

This commit also defines the ATOMIC macro described above and documents
its use in ovs-atomic.h.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Andy Zhou <azhou@nicira.com>
lib/automake.mk
lib/ovs-atomic-gcc4+.c [deleted file]
lib/ovs-atomic-gcc4+.h
lib/ovs-atomic-locked.c [new file with mode: 0644]
lib/ovs-atomic-locked.h [new file with mode: 0644]
lib/ovs-atomic-pthreads.h
lib/ovs-atomic.h