mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-23 08:46:40 +00:00
Work around changes in g_atomic API
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.
This commit is contained in:
parent
c5ae6eed10
commit
f3eac7de22
8 changed files with 48 additions and 22 deletions
|
@ -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 */
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -112,6 +112,7 @@
|
|||
#include <gst/gst.h>
|
||||
#include <stdio.h>
|
||||
#include "gstmultiqueue.h"
|
||||
#include <gst/glib-compat-private.h>
|
||||
|
||||
/**
|
||||
* GstSingleQueue:
|
||||
|
@ -1376,7 +1377,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);
|
||||
|
@ -1482,7 +1483,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);
|
||||
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue