Hi,

It seems that the atomic operation detection does not work for gcc 4.2.1, 
which is the latest version shipped with Xcode. Since the Mac is an important 
platform to support, I hope a workaround can be made for this unfortunately 
very old gcc version.

I do not know the best way to fix this. What I have noticed is that this 
version of gcc does seem to understand the __sync_synchronized() instruction, 
and so if I force the code to compile anyway, regardless of the available 
compiler flags (read: __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4), then the code builds 
and appears to work. At least I can run a complex GStreamer-based app without 
any apparent bugs. This does not prove synchronization is actually happening 
but I hope it is...

Attached is a patch that somewhat forces things to work on Mac. It likely 
breaks other platforms though. Maybe someone else knows enough about this stuff 
to rework it in a way that it could be safe for everyone and be committed to 
glib.

Justin
diff -ru glib-2.32.0.orig/config.h.in glib-2.32.0/config.h.in
--- glib-2.32.0.orig/config.h.in	2012-03-23 20:02:41.000000000 -0700
+++ glib-2.32.0/config.h.in	2012-08-24 18:16:10.000000000 -0700
@@ -168,6 +168,9 @@
 /* Define to 1 if you have the `fsync' function. */
 #undef HAVE_FSYNC
 
+/* we have __sync_synchronize in gcc */
+#undef HAVE_GCC_SYNC_SYNCHRONIZE
+
 /* we have the futex(2) system call */
 #undef HAVE_FUTEX
 
diff -ru glib-2.32.0.orig/configure glib-2.32.0/configure
--- glib-2.32.0.orig/configure	2012-03-23 20:02:40.000000000 -0700
+++ glib-2.32.0/configure	2012-08-24 18:15:08.000000000 -0700
@@ -26787,7 +26787,8 @@
 int
 main ()
 {
-__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4;
+  __sync_synchronize();
+//__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4;
   ;
   return 0;
 }
@@ -26811,7 +26812,8 @@
 int
 main ()
 {
-__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4;
+  __sync_synchronize();
+//__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4;
   ;
   return 0;
 }
@@ -26823,6 +26825,12 @@
   CFLAGS="${SAVE_CFLAGS}"
 fi
 
+if test x"$glib_cv_g_atomic_lock_free" = xyes; then
+
+$as_echo "#define HAVE_GCC_SYNC_SYNCHRONIZE 1" >>confdefs.h
+
+fi
+
 case $host_cpu in
   i?86|x86_64|s390|s390x|arm*|crisv32*|etrax*)
     glib_memory_barrier_needed=no
diff -ru glib-2.32.0.orig/glib/gatomic.c glib-2.32.0/glib/gatomic.c
--- glib-2.32.0.orig/glib/gatomic.c	2012-03-11 17:42:41.000000000 -0700
+++ glib-2.32.0/glib/gatomic.c	2012-08-24 18:21:00.000000000 -0700
@@ -96,7 +96,7 @@
  * implement the atomic operations in a lock-free manner.
  */
 
-#if defined (__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
+#if defined (HAVE_GCC_SYNC_SYNCHRONIZE)
 /**
  * g_atomic_int_get:
  * @atomic: a pointer to a #gint or #guint
diff -ru glib-2.32.0.orig/glib/gatomic.h glib-2.32.0/glib/gatomic.h
--- glib-2.32.0.orig/glib/gatomic.h	2012-03-11 17:42:41.000000000 -0700
+++ glib-2.32.0/glib/gatomic.h	2012-08-24 18:20:44.000000000 -0700
@@ -68,7 +68,7 @@
 
 G_END_DECLS
 
-#if defined(G_ATOMIC_LOCK_FREE) && defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
+#if defined(G_ATOMIC_LOCK_FREE) && defined(HAVE_GCC_SYNC_SYNCHRONIZE)
 
 #define g_atomic_int_get(atomic) \
   (G_GNUC_EXTENSION ({                                                          \
_______________________________________________
gtk-devel-list mailing list
gtk-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-devel-list

Reply via email to