]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/gstreamer0-10.git/commitdiff
Work around changes in g_atomic API
authorDavid Schleef <ds@schleef.org>
Sat, 4 Jun 2011 07:30:15 +0000 (00:30 -0700)
committerTim-Philipp Müller <tim.muller@collabora.co.uk>
Tue, 14 Jun 2011 13:36:36 +0000 (14:36 +0100)
See #651514 for details.  It's apparently impossible to write code
that avoids both type punning warnings with old g_atomic headers and
assertions in the new.  Thus, macros and a version check.

gst/glib-compat-private.h
gst/gstatomicqueue.c
gst/gstelementfactory.c
gst/gstpoll.c
gst/gstsystemclock.c
gst/gstutils.c
plugins/elements/gstmultiqueue.c
tests/benchmarks/gstclockstress.c

index f653ccb96a903e0f2e3c76c4a5cf14f3f7221d1c..7b5d6cf860fb93f4c5e634a9a757599789dfae47 100644 (file)
@@ -26,6 +26,26 @@ typedef struct stat GStatBuf;
 #define GLIB_HAS_GDATETIME
 #endif
 
+/* See bug #651514 */
+#if GLIB_CHECK_VERSION(2,29,5)
+#define G_ATOMIC_POINTER_COMPARE_AND_EXCHANGE(a,b,c) \
+    g_atomic_pointer_compare_and_exchange ((a),(b),(c))
+#define G_ATOMIC_INT_COMPARE_AND_EXCHANGE(a,b,c) \
+    g_atomic_int_compare_and_exchange ((a),(b),(c))
+#else
+#define G_ATOMIC_POINTER_COMPARE_AND_EXCHANGE(a,b,c) \
+    g_atomic_pointer_compare_and_exchange ((volatile gpointer *)(a),(b),(c))
+#define G_ATOMIC_INT_COMPARE_AND_EXCHANGE(a,b,c) \
+    g_atomic_int_compare_and_exchange ((volatile int *)(a),(b),(c))
+#endif
+
+/* See bug #651514 */
+#if GLIB_CHECK_VERSION(2,29,5)
+#define G_ATOMIC_INT_ADD(a,b) g_atomic_int_add ((a),(b))
+#else
+#define G_ATOMIC_INT_ADD(a,b) g_atomic_int_exchange_and_add ((a),(b))
+#endif
+
 /* copies */
 
 /* adaptations */
index 31ac77096a6e8a8b9ba556fc6b4f71c473da5b20..5b21be63eea209cb42551dcbfcc886942a653d64 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <gst/gst.h>
 #include "gstatomicqueue.h"
+#include "glib-compat-private.h"
 
 /**
  * SECTION:gstatomicqueue
@@ -112,8 +113,8 @@ add_to_free_list (GstAtomicQueue * queue, GstAQueueMem * mem)
 {
   do {
     mem->free = g_atomic_pointer_get (&queue->free_list);
-  } while (!g_atomic_pointer_compare_and_exchange ((gpointer *) &
-          queue->free_list, mem->free, mem));
+  } while (!G_ATOMIC_POINTER_COMPARE_AND_EXCHANGE (&queue->free_list,
+          mem->free, mem));
 }
 
 static void
@@ -126,8 +127,8 @@ clear_free_list (GstAtomicQueue * queue)
     free_list = g_atomic_pointer_get (&queue->free_list);
     if (free_list == NULL)
       return;
-  } while (!g_atomic_pointer_compare_and_exchange ((gpointer *) &
-          queue->free_list, free_list, NULL));
+  } while (!G_ATOMIC_POINTER_COMPARE_AND_EXCHANGE (&queue->free_list, free_list,
+          NULL));
 
   while (free_list) {
     GstAQueueMem *next = free_list->free;
@@ -247,8 +248,8 @@ gst_atomic_queue_peek (GstAtomicQueue * queue)
 
     /* now we try to move the next array as the head memory. If we fail to do that,
      * some other reader managed to do it first and we retry */
-    if (!g_atomic_pointer_compare_and_exchange ((gpointer *) &
-            queue->head_mem, head_mem, next))
+    if (!G_ATOMIC_POINTER_COMPARE_AND_EXCHANGE (&queue->head_mem, head_mem,
+            next))
       continue;
 
     /* when we managed to swing the head pointer the old head is now
@@ -304,8 +305,8 @@ gst_atomic_queue_pop (GstAtomicQueue * queue)
 
       /* now we try to move the next array as the head memory. If we fail to do that,
        * some other reader managed to do it first and we retry */
-      if (!g_atomic_pointer_compare_and_exchange ((gpointer *) &
-              queue->head_mem, head_mem, next))
+      if (!G_ATOMIC_POINTER_COMPARE_AND_EXCHANGE (&queue->head_mem, head_mem,
+              next))
         continue;
 
       /* when we managed to swing the head pointer the old head is now
@@ -362,8 +363,8 @@ gst_atomic_queue_push (GstAtomicQueue * queue, gpointer data)
       mem = new_queue_mem ((size << 1) + 1, tail);
 
       /* try to make our new array visible to other writers */
-      if (!g_atomic_pointer_compare_and_exchange ((gpointer *) &
-              queue->tail_mem, tail_mem, mem)) {
+      if (!G_ATOMIC_POINTER_COMPARE_AND_EXCHANGE (&queue->tail_mem, tail_mem,
+              mem)) {
         /* we tried to swap the new writer array but something changed. This is
          * because some other writer beat us to it, we free our memory and try
          * again */
index 0c3d8aae690170b10202ff156e1921d6ae073db8..3549432d8c6d39590736f2c2163137e5b0ea06be 100644 (file)
@@ -394,8 +394,8 @@ gst_element_factory_create (GstElementFactory * factory, const gchar * name)
    * an element at the same moment
    */
   oclass = GST_ELEMENT_GET_CLASS (element);
-  if (!g_atomic_pointer_compare_and_exchange (
-          (gpointer) & oclass->elementfactory, NULL, factory))
+  if (!G_ATOMIC_POINTER_COMPARE_AND_EXCHANGE (&oclass->elementfactory, NULL,
+          factory))
     gst_object_unref (factory);
 
   GST_DEBUG ("created element \"%s\"", GST_PLUGIN_FEATURE_NAME (factory));
index 8bb282a92f0a977264a47006e99d8b7d5a11db5c..d83705940db6f4a80742e6425a0507eb2f3b98ef 100644 (file)
@@ -57,6 +57,7 @@
 #endif
 
 #include "gst_private.h"
+#include "glib-compat-private.h"
 
 #include <sys/types.h>
 
@@ -154,8 +155,8 @@ static gboolean gst_poll_add_fd_unlocked (GstPoll * set, GstPollFD * fd);
 #define IS_FLUSHING(s)      (g_atomic_int_get(&(s)->flushing))
 #define SET_FLUSHING(s,val) (g_atomic_int_set(&(s)->flushing, (val)))
 
-#define INC_WAITING(s)      (g_atomic_int_exchange_and_add(&(s)->waiting, 1))
-#define DEC_WAITING(s)      (g_atomic_int_exchange_and_add(&(s)->waiting, -1))
+#define INC_WAITING(s)      (G_ATOMIC_INT_ADD(&(s)->waiting, 1))
+#define DEC_WAITING(s)      (G_ATOMIC_INT_ADD(&(s)->waiting, -1))
 #define GET_WAITING(s)      (g_atomic_int_get(&(s)->waiting))
 
 #define TEST_REBUILD(s)     (g_atomic_int_compare_and_exchange(&(s)->rebuild, 1, 0))
@@ -176,7 +177,7 @@ raise_wakeup (GstPoll * set)
 {
   gboolean result = TRUE;
 
-  if (g_atomic_int_exchange_and_add (&set->control_pending, 1) == 0) {
+  if (G_ATOMIC_INT_ADD (&set->control_pending, 1) == 0) {
     /* raise when nothing pending */
     result = WAKE_EVENT (set);
   }
@@ -214,7 +215,7 @@ release_all_wakeup (GstPoll * set)
         break;
       else
         /* retry again until we read it successfully */
-        g_atomic_int_exchange_and_add (&set->control_pending, 1);
+        G_ATOMIC_INT_ADD (&set->control_pending, 1);
     }
   }
   return old;
index c197d83b667f71018bbc9bf9c6abb3a692fef30b..7ada0c952bba9a69b7a5c155b362f3edee6785cf 100644 (file)
@@ -44,6 +44,7 @@
 #include "gstenumtypes.h"
 #include "gstpoll.h"
 #include "gstutils.h"
+#include "glib-compat-private.h"
 
 #include <errno.h>
 
@@ -56,8 +57,8 @@
 
 #define GET_ENTRY_STATUS(e)          (g_atomic_int_get(&GST_CLOCK_ENTRY_STATUS(e)))
 #define SET_ENTRY_STATUS(e,val)      (g_atomic_int_set(&GST_CLOCK_ENTRY_STATUS(e),(val)))
-#define CAS_ENTRY_STATUS(e,old,val)  (g_atomic_int_compare_and_exchange(\
-                                       ((volatile gint *)&GST_CLOCK_ENTRY_STATUS(e)), (old), (val)))
+#define CAS_ENTRY_STATUS(e,old,val)  (G_ATOMIC_INT_COMPARE_AND_EXCHANGE(\
+                                       (&GST_CLOCK_ENTRY_STATUS(e)), (old), (val)))
 
 /* Define this to get some extra debug about jitter from each clock_wait */
 #undef WAIT_DEBUGGING
index fcae66e896a55892bf91ae664c2112873b8dcda0..06438cb20d1ea4ac1f7a0bf3b1dbeb664223c018 100644 (file)
@@ -39,6 +39,7 @@
 #include "gstparse.h"
 #include "gstvalue.h"
 #include "gst-i18n-lib.h"
+#include "glib-compat-private.h"
 #include <math.h>
 
 /**
@@ -704,7 +705,7 @@ guint32
 gst_util_seqnum_next (void)
 {
   static gint counter = 0;
-  return g_atomic_int_exchange_and_add (&counter, 1);
+  return G_ATOMIC_INT_ADD (&counter, 1);
 }
 
 /**
index b6b2d245aeaa86c4e921cba1e15182fb712e78bc..541e04235f9d8475573c258a8554c0aed1672dc3 100644 (file)
 #include <gst/gst.h>
 #include <stdio.h>
 #include "gstmultiqueue.h"
+#include <gst/glib-compat-private.h>
 
 /**
  * GstSingleQueue:
@@ -1240,7 +1241,7 @@ gst_multi_queue_chain (GstPad * pad, GstBuffer * buffer)
     goto was_eos;
 
   /* Get a unique incrementing id */
-  curid = g_atomic_int_exchange_and_add ((gint *) & mq->counter, 1);
+  curid = G_ATOMIC_INT_ADD ((gint *) & mq->counter, 1);
 
   GST_LOG_OBJECT (mq, "SingleQueue %d : about to enqueue buffer %p with id %d",
       sq->id, buffer, curid);
@@ -1346,7 +1347,7 @@ gst_multi_queue_sink_event (GstPad * pad, GstEvent * event)
     goto was_eos;
 
   /* Get an unique incrementing id. */
-  curid = g_atomic_int_exchange_and_add ((gint *) & mq->counter, 1);
+  curid = G_ATOMIC_INT_ADD ((gint *) & mq->counter, 1);
 
   item = gst_multi_queue_event_item_new ((GstMiniObject *) event, curid);
 
index 6c1895cd27599200e28ba6c4b877547e664c5a3c..b0f721b3d531034eead5e25c810b868564df71b5 100644 (file)
@@ -20,6 +20,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <gst/gst.h>
+#include <gst/glib-compat-private.h>
 
 #define MAX_THREADS  100
 
@@ -34,7 +35,7 @@ run_test (void *user_data)
 
   while (running) {
     gst_clock_get_time (sysclock);
-    prev = g_atomic_int_exchange_and_add (&count, 1);
+    prev = G_ATOMIC_INT_ADD (&count, 1);
     if (prev == G_MAXINT)
       g_warning ("overflow");
   }