Acked-by: Andy Zhou <az...@nicira.com>

On Tue, Mar 11, 2014 at 1:56 PM, Ben Pfaff <b...@nicira.com> wrote:

> This reduces duplicate code.
>
> Signed-off-by: Ben Pfaff <b...@nicira.com>
> ---
>  lib/automake.mk           |    1 +
>  lib/ovs-atomic-c11.h      |   15 ++++-----------
>  lib/ovs-atomic-clang.h    |   42 +++-------------------------------------
>  lib/ovs-atomic-gcc4.7+.h  |   44
> +++---------------------------------------
>  lib/ovs-atomic-pthreads.h |   45
> +++----------------------------------------
>  lib/ovs-atomic-types.h    |   47
> +++++++++++++++++++++++++++++++++++++++++++++
>  6 files changed, 61 insertions(+), 133 deletions(-)
>  create mode 100644 lib/ovs-atomic-types.h
>
> diff --git a/lib/automake.mk b/lib/automake.mk
> index 476421c..3b2b75f 100644
> --- a/lib/automake.mk
> +++ b/lib/automake.mk
> @@ -139,6 +139,7 @@ lib_libopenvswitch_la_SOURCES = \
>         lib/ovs-atomic-gcc4.7+.h \
>         lib/ovs-atomic-pthreads.c \
>         lib/ovs-atomic-pthreads.h \
> +       lib/ovs-atomic-types.h \
>         lib/ovs-atomic.h \
>         lib/ovs-thread.c \
>         lib/ovs-thread.h \
> diff --git a/lib/ovs-atomic-c11.h b/lib/ovs-atomic-c11.h
> index 97262b2..96aec7c 100644
> --- a/lib/ovs-atomic-c11.h
> +++ b/lib/ovs-atomic-c11.h
> @@ -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.
> @@ -22,16 +22,9 @@
>
>  #include <stdatomic.h>
>
> -/* Nonstandard atomic types. */
> -typedef _Atomic(uint8_t)   atomic_uint8_t;
> -typedef _Atomic(uint16_t)  atomic_uint16_t;
> -typedef _Atomic(uint32_t)  atomic_uint32_t;
> -typedef _Atomic(uint64_t)  atomic_uint64_t;
> -
> -typedef _Atomic(int8_t)    atomic_int8_t;
> -typedef _Atomic(int16_t)   atomic_int16_t;
> -typedef _Atomic(int32_t)   atomic_int32_t;
> -typedef _Atomic(int64_t)   atomic_int64_t;
> +#define OMIT_STANDARD_ATOMIC_TYPES 1
> +#define ATOMIC(TYPE) _Atomic(TYPE)
> +#include "ovs-atomic-types.h"
>
>  #define atomic_read(SRC, DST) \
>      atomic_read_explicit(SRC, DST, memory_order_seq_cst)
> diff --git a/lib/ovs-atomic-clang.h b/lib/ovs-atomic-clang.h
> index 7449428..c169f37 100644
> --- a/lib/ovs-atomic-clang.h
> +++ b/lib/ovs-atomic-clang.h
> @@ -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.
> @@ -21,44 +21,8 @@
>
>  #define OVS_ATOMIC_CLANG_IMPL 1
>
> -/* Standard atomic types. */
> -typedef _Atomic(_Bool) atomic_bool;
> -
> -typedef _Atomic(char) atomic_char;
> -typedef _Atomic(signed char) atomic_schar;
> -typedef _Atomic(unsigned char) atomic_uchar;
> -
> -typedef _Atomic(short) atomic_short;
> -typedef _Atomic(unsigned short) atomic_ushort;
> -
> -typedef _Atomic(int) atomic_int;
> -typedef _Atomic(unsigned int) atomic_uint;
> -
> -typedef _Atomic(long) atomic_long;
> -typedef _Atomic(unsigned long) atomic_ulong;
> -
> -typedef _Atomic(long long) atomic_llong;
> -typedef _Atomic(unsigned long long) atomic_ullong;
> -
> -typedef _Atomic(size_t) atomic_size_t;
> -typedef _Atomic(ptrdiff_t) atomic_ptrdiff_t;
> -
> -typedef _Atomic(intmax_t) atomic_intmax_t;
> -typedef _Atomic(uintmax_t) atomic_uintmax_t;
> -
> -typedef _Atomic(intptr_t) atomic_intptr_t;
> -typedef _Atomic(uintptr_t) atomic_uintptr_t;
> -
> -/* Nonstandard atomic types. */
> -typedef _Atomic(uint8_t)   atomic_uint8_t;
> -typedef _Atomic(uint16_t)  atomic_uint16_t;
> -typedef _Atomic(uint32_t)  atomic_uint32_t;
> -typedef _Atomic(uint64_t)  atomic_uint64_t;
> -
> -typedef _Atomic(int8_t)    atomic_int8_t;
> -typedef _Atomic(int16_t)   atomic_int16_t;
> -typedef _Atomic(int32_t)   atomic_int32_t;
> -typedef _Atomic(int64_t)   atomic_int64_t;
> +#define ATOMIC(TYPE) _Atomic(TYPE)
> +#include "ovs-atomic-types.h"
>
>  #define ATOMIC_VAR_INIT(VALUE) (VALUE)
>
> diff --git a/lib/ovs-atomic-gcc4.7+.h b/lib/ovs-atomic-gcc4.7+.h
> index 56d265f..da88558 100644
> --- a/lib/ovs-atomic-gcc4.7+.h
> +++ b/lib/ovs-atomic-gcc4.7+.h
> @@ -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.
> @@ -19,46 +19,8 @@
>  #error "This header should only be included indirectly via ovs-atomic.h."
>  #endif
>
> -/* C11 standardized atomic type. */
> -typedef bool               atomic_bool;
> -
> -typedef char               atomic_char;
> -typedef signed char        atomic_schar;
> -typedef unsigned char      atomic_uchar;
> -
> -typedef short              atomic_short;
> -typedef unsigned short     atomic_ushort;
> -
> -typedef int                atomic_int;
> -typedef unsigned int       atomic_uint;
> -
> -typedef long               atomic_long;
> -typedef unsigned long      atomic_ulong;
> -
> -typedef long long          atomic_llong;
> -typedef unsigned long long atomic_ullong;
> -
> -typedef size_t             atomic_size_t;
> -typedef ptrdiff_t          atomic_ptrdiff_t;
> -
> -typedef intmax_t           atomic_intmax_t;
> -typedef uintmax_t          atomic_uintmax_t;
> -
> -typedef intptr_t           atomic_intptr_t;
> -typedef uintptr_t          atomic_uintptr_t;
> -
> -/* Nonstandard atomic types. */
> -typedef int8_t             atomic_int8_t;
> -typedef uint8_t            atomic_uint8_t;
> -
> -typedef int16_t            atomic_int16_t;
> -typedef uint16_t           atomic_uint16_t;
> -
> -typedef int32_t            atomic_int32_t;
> -typedef uint32_t           atomic_uint32_t;
> -
> -typedef int64_t            atomic_int64_t;
> -typedef uint64_t           atomic_uint64_t;
> +#define ATOMIC(TYPE) TYPE
> +#include "ovs-atomic-types.h"
>
>  typedef enum {
>      memory_order_relaxed = __ATOMIC_RELAXED,
> diff --git a/lib/ovs-atomic-pthreads.h b/lib/ovs-atomic-pthreads.h
> index dc8f498..ff39925 100644
> --- a/lib/ovs-atomic-pthreads.h
> +++ b/lib/ovs-atomic-pthreads.h
> @@ -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.
> @@ -21,55 +21,16 @@
>
>  #define OVS_ATOMIC_PTHREADS_IMPL 1
>
> -#define DEFINE_PTHREAD_ATOMIC(TYPE, NAME)       \
> -    typedef struct {                            \
> -        TYPE value;                             \
> -        pthread_mutex_t mutex;                  \
> -    } NAME;
> +#define ATOMIC(TYPE) struct { TYPE value; pthread_mutex_t mutex; }
> +#include "ovs-atomic-types.h"
>
>  #define ATOMIC_BOOL_LOCK_FREE 0
> -DEFINE_PTHREAD_ATOMIC(bool, atomic_bool);
> -
>  #define ATOMIC_CHAR_LOCK_FREE 0
> -DEFINE_PTHREAD_ATOMIC(char, atomic_char);
> -DEFINE_PTHREAD_ATOMIC(signed char, atomic_schar);
> -DEFINE_PTHREAD_ATOMIC(unsigned char, atomic_uchar);
> -
>  #define ATOMIC_SHORT_LOCK_FREE 0
> -DEFINE_PTHREAD_ATOMIC(short, atomic_short);
> -DEFINE_PTHREAD_ATOMIC(unsigned short, atomic_ushort);
> -
>  #define ATOMIC_INT_LOCK_FREE 0
> -DEFINE_PTHREAD_ATOMIC(int, atomic_int);
> -DEFINE_PTHREAD_ATOMIC(unsigned int, atomic_uint);
> -
>  #define ATOMIC_LONG_LOCK_FREE 0
> -DEFINE_PTHREAD_ATOMIC(long, atomic_long);
> -DEFINE_PTHREAD_ATOMIC(unsigned long, atomic_ulong);
> -
>  #define ATOMIC_LLONG_LOCK_FREE 0
> -DEFINE_PTHREAD_ATOMIC(long long, atomic_llong);
> -DEFINE_PTHREAD_ATOMIC(unsigned long long, atomic_ullong);
> -
> -DEFINE_PTHREAD_ATOMIC(size_t, atomic_size_t);
> -DEFINE_PTHREAD_ATOMIC(ptrdiff_t, atomic_ptrdiff_t);
> -
> -DEFINE_PTHREAD_ATOMIC(intmax_t, atomic_intmax_t);
> -DEFINE_PTHREAD_ATOMIC(uintmax_t, atomic_uintmax_t);
> -
>  #define ATOMIC_POINTER_LOCK_FREE 0
> -DEFINE_PTHREAD_ATOMIC(intptr_t, atomic_intptr_t);
> -DEFINE_PTHREAD_ATOMIC(uintptr_t, atomic_uintptr_t);
> -
> -/* Nonstandard atomic types. */
> -DEFINE_PTHREAD_ATOMIC(uint8_t,  atomic_uint8_t);
> -DEFINE_PTHREAD_ATOMIC(uint16_t, atomic_uint16_t);
> -DEFINE_PTHREAD_ATOMIC(uint32_t, atomic_uint32_t);
> -DEFINE_PTHREAD_ATOMIC(int8_t,   atomic_int8_t);
> -DEFINE_PTHREAD_ATOMIC(int16_t,  atomic_int16_t);
> -DEFINE_PTHREAD_ATOMIC(int32_t,  atomic_int32_t);
> -DEFINE_PTHREAD_ATOMIC(uint64_t, atomic_uint64_t);
> -DEFINE_PTHREAD_ATOMIC(int64_t,  atomic_int64_t);
>
>  typedef enum {
>      memory_order_relaxed,
> diff --git a/lib/ovs-atomic-types.h b/lib/ovs-atomic-types.h
> new file mode 100644
> index 0000000..bbce476
> --- /dev/null
> +++ b/lib/ovs-atomic-types.h
> @@ -0,0 +1,47 @@
> +/* This header defines atomic_* types using an ATOMIC macro provided by
> the
> +* caller. */
> +#ifndef IN_OVS_ATOMIC_H
> +#error "This header should only be included indirectly via ovs-atomic.h."
> +#endif
> +
> +#ifndef OMIT_STANDARD_ATOMIC_TYPES
> +typedef ATOMIC(bool)               atomic_bool;
> +
> +typedef ATOMIC(char)               atomic_char;
> +typedef ATOMIC(signed char)        atomic_schar;
> +typedef ATOMIC(unsigned char)      atomic_uchar;
> +
> +typedef ATOMIC(short)              atomic_short;
> +typedef ATOMIC(unsigned short)     atomic_ushort;
> +
> +typedef ATOMIC(int)                atomic_int;
> +typedef ATOMIC(unsigned int)       atomic_uint;
> +
> +typedef ATOMIC(long)               atomic_long;
> +typedef ATOMIC(unsigned long)      atomic_ulong;
> +
> +typedef ATOMIC(long long)          atomic_llong;
> +typedef ATOMIC(unsigned long long) atomic_ullong;
> +
> +typedef ATOMIC(size_t)             atomic_size_t;
> +typedef ATOMIC(ptrdiff_t)          atomic_ptrdiff_t;
> +
> +typedef ATOMIC(intmax_t)           atomic_intmax_t;
> +typedef ATOMIC(uintmax_t)          atomic_uintmax_t;
> +
> +typedef ATOMIC(intptr_t)           atomic_intptr_t;
> +typedef ATOMIC(uintptr_t)          atomic_uintptr_t;
> +#endif  /* !OMIT_STANDARD_ATOMIC_TYPES */
> +
> +/* Nonstandard atomic types. */
> +typedef ATOMIC(uint8_t)   atomic_uint8_t;
> +typedef ATOMIC(uint16_t)  atomic_uint16_t;
> +typedef ATOMIC(uint32_t)  atomic_uint32_t;
> +typedef ATOMIC(uint64_t)  atomic_uint64_t;
> +
> +typedef ATOMIC(int8_t)    atomic_int8_t;
> +typedef ATOMIC(int16_t)   atomic_int16_t;
> +typedef ATOMIC(int32_t)   atomic_int32_t;
> +typedef ATOMIC(int64_t)   atomic_int64_t;
> +
> +#undef OMIT_STANDARD_ATOMIC_TYPES
> --
> 1.7.10.4
>
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev
>
_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to