Use G_STATIC_ASSERT_EXPR for size checks in atomic macros

Also add the same size checks to the macros wrapping
gcc builtins.
This commit is contained in:
Matthias Clasen 2011-05-28 00:04:10 -04:00
parent edd65baa6d
commit 7cf1122253

View File

@ -59,28 +59,36 @@ void g_atomic_pointer_set (volatile gpointer G_GNUC_MAY_ALI
#if defined(__GNUC__) && defined(G_ATOMIC_OP_USE_GCC_BUILTINS)
#define g_atomic_int_exchange_and_add(atomic,val) \
__sync_fetch_and_add((atomic),(val))
__extension__ ({ G_STATIC_ASSERT_EXPR(sizeof (*(atomic)) == sizeof (gint)); \
__sync_fetch_and_add((atomic),(val)); })
#define g_atomic_int_add(atomic,val) \
__sync_fetch_and_add((atomic),(val))
__extension__ ({ G_STATIC_ASSERT_EXPR(sizeof (*(atomic)) == sizeof (gint)); \
__sync_fetch_and_add((atomic),(val)); })
#define g_atomic_int_compare_and_exchange(atomic,oldval,newval) \
__sync_bool_compare_and_swap((atomic),(oldval),(newval))
__extension__ ({ G_STATIC_ASSERT_EXPR(sizeof (*(atomic)) == sizeof (gint)); \
__sync_bool_compare_and_swap((atomic),(oldval),(newval)); })
#define g_atomic_int_get(atomic) \
__extension__ ({ __sync_synchronize(); *(atomic); })
__extension__ ({ G_STATIC_ASSERT_EXPR(sizeof (*(atomic)) == sizeof (gint)); \
__sync_synchronize(); *(atomic); })
#define g_atomic_int_set(atomic,newval) \
__extension__ ({ *(atomic) = (newval); __sync_synchronize(); })
__extension__ ({ G_STATIC_ASSERT_EXPR(sizeof (*(atomic)) == sizeof (gint)); \
*(atomic) = (newval); __sync_synchronize(); })
#define g_atomic_pointer_compare_and_exchange(atomic,oldval,newval) \
__sync_bool_compare_and_swap((atomic),(oldval),(newval))
__extension__ ({ G_STATIC_ASSERT_EXPR(sizeof (*(atomic)) == sizeof (gpointer)); \
__sync_bool_compare_and_swap((atomic),(oldval),(newval)); })
#define g_atomic_pointer_get(atomic) \
__extension__ ({ __sync_synchronize(); *(atomic); })
__extension__ ({ G_STATIC_ASSERT_EXPR(sizeof (*(atomic)) == sizeof (gpointer)); \
__sync_synchronize(); *(atomic); })
#define g_atomic_pointer_set(atomic,newval) \
__extension__ ({ *(atomic) = (newval); __sync_synchronize(); })
__extension__ ({ G_STATIC_ASSERT_EXPR(sizeof (*(atomic)) == sizeof (gpointer)); \
*(atomic) = (newval); __sync_synchronize(); })
#elif !defined(G_ATOMIC_OP_MEMORY_BARRIER_NEEDED)
@ -92,16 +100,16 @@ void g_atomic_pointer_set (volatile gpointer G_GNUC_MAY_ALI
#else
# define g_atomic_int_get(atomic) \
((void) sizeof (gchar [sizeof (*(atomic)) == sizeof (gint) ? 1 : -1]), \
(G_STATIC_ASSERT_EXPR(sizeof (*(atomic)) == sizeof (gint)), \
(g_atomic_int_get) ((volatile gint G_GNUC_MAY_ALIAS *) (volatile void *) (atomic)))
# define g_atomic_int_set(atomic, newval) \
((void) sizeof (gchar [sizeof (*(atomic)) == sizeof (gint) ? 1 : -1]), \
(G_STATIC_ASSERT_EXPR(sizeof (*(atomic)) == sizeof (gint)), \
(g_atomic_int_set) ((volatile gint G_GNUC_MAY_ALIAS *) (volatile void *) (atomic), (newval)))
# define g_atomic_pointer_get(atomic) \
((void) sizeof (gchar [sizeof (*(atomic)) == sizeof (gpointer) ? 1 : -1]), \
(G_STATIC_ASSERT_EXPR(sizeof (*(atomic)) == sizeof (gpointer)), \
(g_atomic_pointer_get) ((volatile gpointer G_GNUC_MAY_ALIAS *) (volatile void *) (atomic)))
# define g_atomic_pointer_set(atomic, newval) \
((void) sizeof (gchar [sizeof (*(atomic)) == sizeof (gpointer) ? 1 : -1]), \
(G_STATIC_ASSERT_EXPR(sizeof (*(atomic)) == sizeof (gpointer)), \
(g_atomic_pointer_set) ((volatile gpointer G_GNUC_MAY_ALIAS *) (volatile void *) (atomic), (newval)))
#endif /* G_ATOMIC_OP_MEMORY_BARRIER_NEEDED */