Skip to content
  • Ben Pfaff's avatar
    ovs-atomic: Use raw types, not structs, when locks are required. · 1bd2c9ed
    Ben Pfaff authored
    
    
    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: default avatarBen Pfaff <blp@nicira.com>
    Acked-by: default avatarAndy Zhou <azhou@nicira.com>
    1bd2c9ed