summaryrefslogtreecommitdiff
path: root/glib/gatomic.h
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2011-05-28 00:04:10 -0400
committerMatthias Clasen <mclasen@redhat.com>2011-05-28 00:04:10 -0400
commit7cf112225399ffa262082727bf4f434d57568e30 (patch)
treeff72c0a5f0a64aa6c22cc4688472e941c1f4a4ef /glib/gatomic.h
parentedd65baa6d9f6b951f093a15b6fcb5771e3397e0 (diff)
downloadglib-7cf112225399ffa262082727bf4f434d57568e30.tar.gz
Use G_STATIC_ASSERT_EXPR for size checks in atomic macros
Also add the same size checks to the macros wrapping gcc builtins.
Diffstat (limited to 'glib/gatomic.h')
-rw-r--r--glib/gatomic.h50
1 files changed, 29 insertions, 21 deletions
diff --git a/glib/gatomic.h b/glib/gatomic.h
index 969443a0f..9c85607bd 100644
--- a/glib/gatomic.h
+++ b/glib/gatomic.h
@@ -39,48 +39,56 @@
G_BEGIN_DECLS
gint g_atomic_int_exchange_and_add (volatile gint G_GNUC_MAY_ALIAS *atomic,
- gint val);
+ gint val);
void g_atomic_int_add (volatile gint G_GNUC_MAY_ALIAS *atomic,
- gint val);
+ gint val);
gboolean g_atomic_int_compare_and_exchange (volatile gint G_GNUC_MAY_ALIAS *atomic,
- gint oldval,
- gint newval);
-gboolean g_atomic_pointer_compare_and_exchange (volatile gpointer G_GNUC_MAY_ALIAS *atomic,
- gpointer oldval,
- gpointer newval);
+ gint oldval,
+ gint newval);
+gboolean g_atomic_pointer_compare_and_exchange (volatile gpointer G_GNUC_MAY_ALIAS *atomic,
+ gpointer oldval,
+ gpointer newval);
gint g_atomic_int_get (volatile gint G_GNUC_MAY_ALIAS *atomic);
void g_atomic_int_set (volatile gint G_GNUC_MAY_ALIAS *atomic,
- gint newval);
+ gint newval);
gpointer g_atomic_pointer_get (volatile gpointer G_GNUC_MAY_ALIAS *atomic);
void g_atomic_pointer_set (volatile gpointer G_GNUC_MAY_ALIAS *atomic,
- gpointer newval);
+ gpointer newval);
#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 */