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