glib/glib/gatomic.c
branchGCC_SURGE
changeset 42 a16d1cd191f6
parent 35 f27f6b44bd0d
equal deleted inserted replaced
39:4393da0c39b5 42:a16d1cd191f6
    38 #define g_thread_use_default_impl (*_g_thread_use_default_impl())
    38 #define g_thread_use_default_impl (*_g_thread_use_default_impl())
    39 #endif /* EMULATOR */
    39 #endif /* EMULATOR */
    40 
    40 
    41 
    41 
    42 #if defined (__GNUC__)
    42 #if defined (__GNUC__)
    43 #define GCC_VERSION (__GNUC__ * 10000 \
    43 # if defined (G_ATOMIC_I486)
    44                                + __GNUC_MINOR__ * 100 \
       
    45                                + __GNUC_PATCHLEVEL__)
       
    46 
       
    47 /* Test for GCC > 4.4.0 */
       
    48 # if (GCC_VERSION > 40400)
       
    49 
       
    50 EXPORT_C gint
       
    51 g_atomic_int_exchange_and_add (volatile gint *atomic,
       
    52 			       gint           val)
       
    53 {
       
    54    return __sync_fetch_and_add(atomic, val);
       
    55 }
       
    56 
       
    57 EXPORT_C void
       
    58 g_atomic_int_add (volatile gint *atomic,
       
    59 		  gint           val)
       
    60 {
       
    61    __sync_fetch_and_add(atomic, val);
       
    62 }
       
    63 
       
    64 EXPORT_C gboolean
       
    65 g_atomic_int_compare_and_exchange (volatile gint *atomic,
       
    66 				   gint           oldval,
       
    67 				   gint           newval)
       
    68 {
       
    69   return __sync_val_compare_and_swap(atomic, oldval, newval);
       
    70 }
       
    71 
       
    72 EXPORT_C gboolean
       
    73 g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic,
       
    74 				       gpointer           oldval,
       
    75 				       gpointer           newval)
       
    76 {
       
    77   return __sync_val_compare_and_swap(atomic, oldval, newval);
       
    78 }
       
    79 
       
    80 #elif defined (G_ATOMIC_I486)
       
    81 /* Adapted from CVS version 1.10 of glibc's sysdeps/i386/i486/bits/atomic.h 
    44 /* Adapted from CVS version 1.10 of glibc's sysdeps/i386/i486/bits/atomic.h 
    82  */
    45  */
    83 EXPORT_C gint
    46 EXPORT_C gint
    84 g_atomic_int_exchange_and_add (volatile gint G_GNUC_MAY_ALIAS *atomic, 
    47 g_atomic_int_exchange_and_add (volatile gint G_GNUC_MAY_ALIAS *atomic, 
    85 			       gint           val)
    48 			       gint           val)