mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-09 19:09:41 +00:00
libs: use g_clear_object() wherever applicable.
This is a preferred thread-safe version. Also add an inline version of g_clear_object() if compiling with glib < 2.28. Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
This commit is contained in:
parent
c415868f26
commit
30024b3f8e
10 changed files with 32 additions and 50 deletions
|
@ -23,6 +23,7 @@
|
|||
#define GLIB_COMPAT_H
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
|
||||
#if !GLIB_CHECK_VERSION(2,27,2)
|
||||
static inline void
|
||||
|
@ -33,6 +34,24 @@ g_list_free_full(GList *list, GDestroyNotify free_func)
|
|||
}
|
||||
#endif
|
||||
|
||||
#if !GLIB_CHECK_VERSION(2,28,0)
|
||||
static inline void
|
||||
g_clear_object_inline(volatile GObject **object_ptr)
|
||||
{
|
||||
gpointer * const ptr = (gpointer)object_ptr;
|
||||
gpointer old;
|
||||
|
||||
do {
|
||||
old = g_atomic_pointer_get(ptr);
|
||||
} while G_UNLIKELY(!g_atomic_pointer_compare_and_exchange(ptr, old, NULL));
|
||||
|
||||
if (old)
|
||||
g_object_unref(old);
|
||||
}
|
||||
#undef g_clear_object
|
||||
#define g_clear_object(obj) g_clear_object_inline((volatile GObject **)(obj))
|
||||
#endif
|
||||
|
||||
#if GLIB_CHECK_VERSION(2,31,2)
|
||||
#define GStaticMutex GMutex
|
||||
#undef g_static_mutex_init
|
||||
|
|
|
@ -158,10 +158,7 @@ gst_vaapi_context_destroy_surfaces(GstVaapiContext *context)
|
|||
priv->surfaces = NULL;
|
||||
}
|
||||
|
||||
if (priv->surfaces_pool) {
|
||||
g_object_unref(priv->surfaces_pool);
|
||||
priv->surfaces_pool = NULL;
|
||||
}
|
||||
g_clear_object(&priv->surfaces_pool);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -352,10 +352,7 @@ gst_vaapi_display_destroy(GstVaapiDisplay *display)
|
|||
klass->close_display(display);
|
||||
}
|
||||
|
||||
if (priv->parent) {
|
||||
g_object_unref(priv->parent);
|
||||
priv->parent = NULL;
|
||||
}
|
||||
g_clear_object(&priv->parent);
|
||||
|
||||
if (g_display_cache) {
|
||||
gst_vaapi_display_cache_remove(get_display_cache(), display);
|
||||
|
@ -408,8 +405,7 @@ gst_vaapi_display_create(GstVaapiDisplay *display)
|
|||
info.va_display
|
||||
);
|
||||
if (cached_info) {
|
||||
if (priv->parent)
|
||||
g_object_unref(priv->parent);
|
||||
g_clear_object(&priv->parent);
|
||||
priv->parent = g_object_ref(cached_info->display);
|
||||
}
|
||||
|
||||
|
|
|
@ -71,10 +71,7 @@ gst_vaapi_object_finalize(GObject *object)
|
|||
|
||||
priv->id = GST_VAAPI_ID_NONE;
|
||||
|
||||
if (priv->display) {
|
||||
g_object_unref(priv->display);
|
||||
priv->display = NULL;
|
||||
}
|
||||
g_clear_object(&priv->display);
|
||||
|
||||
G_OBJECT_CLASS(gst_vaapi_object_parent_class)->finalize(object);
|
||||
}
|
||||
|
|
|
@ -79,10 +79,7 @@ gst_vaapi_subpicture_destroy(GstVaapiSubpicture *subpicture)
|
|||
GST_VAAPI_OBJECT_ID(subpicture) = VA_INVALID_ID;
|
||||
}
|
||||
|
||||
if (priv->image) {
|
||||
g_object_unref(priv->image);
|
||||
priv->image = NULL;
|
||||
}
|
||||
g_clear_object(&priv->image);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
|
@ -444,10 +444,7 @@ gst_vaapi_surface_set_parent_context(
|
|||
|
||||
priv = surface->priv;
|
||||
|
||||
if (priv->parent_context) {
|
||||
g_object_unref(priv->parent_context);
|
||||
priv->parent_context = NULL;
|
||||
}
|
||||
g_clear_object(&priv->parent_context);
|
||||
|
||||
if (context)
|
||||
priv->parent_context = g_object_ref(context);
|
||||
|
|
|
@ -260,10 +260,7 @@ gst_vaapi_surface_proxy_set_context(
|
|||
|
||||
priv = proxy->priv;
|
||||
|
||||
if (priv->context) {
|
||||
g_object_unref(priv->context);
|
||||
priv->context = NULL;
|
||||
}
|
||||
g_clear_object(&priv->context);
|
||||
|
||||
if (context)
|
||||
priv->context = g_object_ref(context);
|
||||
|
|
|
@ -58,10 +58,7 @@ set_display(GstVaapiVideoBuffer *buffer, GstVaapiDisplay *display)
|
|||
{
|
||||
GstVaapiVideoBufferPrivate * const priv = buffer->priv;
|
||||
|
||||
if (priv->display) {
|
||||
g_object_unref(priv->display);
|
||||
priv->display = NULL;
|
||||
}
|
||||
g_clear_object(&priv->display);
|
||||
|
||||
if (display)
|
||||
priv->display = g_object_ref(display);
|
||||
|
@ -94,10 +91,7 @@ gst_vaapi_video_buffer_destroy_image(GstVaapiVideoBuffer *buffer)
|
|||
priv->image = NULL;
|
||||
}
|
||||
|
||||
if (priv->image_pool) {
|
||||
g_object_unref(priv->image_pool);
|
||||
priv->image_pool = NULL;
|
||||
}
|
||||
g_clear_object(&priv->image_pool);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -105,10 +99,7 @@ gst_vaapi_video_buffer_destroy_surface(GstVaapiVideoBuffer *buffer)
|
|||
{
|
||||
GstVaapiVideoBufferPrivate * const priv = buffer->priv;
|
||||
|
||||
if (priv->proxy) {
|
||||
g_object_unref(priv->proxy);
|
||||
priv->proxy = NULL;
|
||||
}
|
||||
g_clear_object(&priv->proxy);
|
||||
|
||||
if (priv->surface) {
|
||||
if (priv->surface_pool)
|
||||
|
@ -118,10 +109,7 @@ gst_vaapi_video_buffer_destroy_surface(GstVaapiVideoBuffer *buffer)
|
|||
priv->surface = NULL;
|
||||
}
|
||||
|
||||
if (priv->surface_pool) {
|
||||
g_object_unref(priv->surface_pool);
|
||||
priv->surface_pool = NULL;
|
||||
}
|
||||
g_clear_object(&priv->surface_pool);
|
||||
|
||||
if (priv->buffer) {
|
||||
gst_buffer_unref(priv->buffer);
|
||||
|
|
|
@ -44,10 +44,7 @@ gst_vaapi_video_converter_glx_dispose(GObject *object)
|
|||
GstVaapiVideoConverterGLXPrivate *priv =
|
||||
GST_VAAPI_VIDEO_CONVERTER_GLX (object)->priv;
|
||||
|
||||
if (priv->texture)
|
||||
g_object_unref (priv->texture);
|
||||
|
||||
priv->texture = NULL;
|
||||
g_clear_object(&priv->texture);
|
||||
|
||||
G_OBJECT_CLASS (gst_vaapi_video_converter_glx_parent_class)->dispose (object);
|
||||
}
|
||||
|
|
|
@ -95,10 +95,7 @@ gst_vaapi_video_pool_destroy(GstVaapiVideoPool *pool)
|
|||
priv->caps = NULL;
|
||||
}
|
||||
|
||||
if (priv->display) {
|
||||
g_object_unref(priv->display);
|
||||
priv->display = NULL;
|
||||
}
|
||||
g_clear_object(&priv->display);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
Loading…
Reference in a new issue