summaryrefslogtreecommitdiff
path: root/gst-libs/gst
diff options
context:
space:
mode:
authorJavier Jardón <jjardon@gnome.org>2012-07-01 05:34:15 +0900
committerGwenole Beauchesne <gwenole.beauchesne@intel.com>2012-07-19 15:19:17 +0200
commit30024b3f8e2de95c0ba31fc4989f45249bd9d070 (patch)
tree0a708011fc123cf9fbd60b126da6a059297677b4 /gst-libs/gst
parentc415868f269745c5c87c025681f5ee19feaba278 (diff)
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>
Diffstat (limited to 'gst-libs/gst')
-rw-r--r--gst-libs/gst/vaapi/glibcompat.h19
-rw-r--r--gst-libs/gst/vaapi/gstvaapicontext.c5
-rw-r--r--gst-libs/gst/vaapi/gstvaapidisplay.c8
-rw-r--r--gst-libs/gst/vaapi/gstvaapiobject.c5
-rw-r--r--gst-libs/gst/vaapi/gstvaapisubpicture.c5
-rw-r--r--gst-libs/gst/vaapi/gstvaapisurface.c5
-rw-r--r--gst-libs/gst/vaapi/gstvaapisurfaceproxy.c5
-rw-r--r--gst-libs/gst/vaapi/gstvaapivideobuffer.c20
-rw-r--r--gst-libs/gst/vaapi/gstvaapivideoconverter_glx.c5
-rw-r--r--gst-libs/gst/vaapi/gstvaapivideopool.c5
10 files changed, 32 insertions, 50 deletions
diff --git a/gst-libs/gst/vaapi/glibcompat.h b/gst-libs/gst/vaapi/glibcompat.h
index 93a3903c..30a8563f 100644
--- a/gst-libs/gst/vaapi/glibcompat.h
+++ b/gst-libs/gst/vaapi/glibcompat.h
@@ -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
diff --git a/gst-libs/gst/vaapi/gstvaapicontext.c b/gst-libs/gst/vaapi/gstvaapicontext.c
index 9b1bf1ad..52e81e40 100644
--- a/gst-libs/gst/vaapi/gstvaapicontext.c
+++ b/gst-libs/gst/vaapi/gstvaapicontext.c
@@ -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
diff --git a/gst-libs/gst/vaapi/gstvaapidisplay.c b/gst-libs/gst/vaapi/gstvaapidisplay.c
index 01e19fcd..e113f71e 100644
--- a/gst-libs/gst/vaapi/gstvaapidisplay.c
+++ b/gst-libs/gst/vaapi/gstvaapidisplay.c
@@ -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);
}
diff --git a/gst-libs/gst/vaapi/gstvaapiobject.c b/gst-libs/gst/vaapi/gstvaapiobject.c
index ec8286e7..ad3d139b 100644
--- a/gst-libs/gst/vaapi/gstvaapiobject.c
+++ b/gst-libs/gst/vaapi/gstvaapiobject.c
@@ -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);
}
diff --git a/gst-libs/gst/vaapi/gstvaapisubpicture.c b/gst-libs/gst/vaapi/gstvaapisubpicture.c
index 11a94f10..cfd7fd3a 100644
--- a/gst-libs/gst/vaapi/gstvaapisubpicture.c
+++ b/gst-libs/gst/vaapi/gstvaapisubpicture.c
@@ -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
diff --git a/gst-libs/gst/vaapi/gstvaapisurface.c b/gst-libs/gst/vaapi/gstvaapisurface.c
index 65c4b28e..b471de7d 100644
--- a/gst-libs/gst/vaapi/gstvaapisurface.c
+++ b/gst-libs/gst/vaapi/gstvaapisurface.c
@@ -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);
diff --git a/gst-libs/gst/vaapi/gstvaapisurfaceproxy.c b/gst-libs/gst/vaapi/gstvaapisurfaceproxy.c
index 3c2f2299..aa4103e0 100644
--- a/gst-libs/gst/vaapi/gstvaapisurfaceproxy.c
+++ b/gst-libs/gst/vaapi/gstvaapisurfaceproxy.c
@@ -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);
diff --git a/gst-libs/gst/vaapi/gstvaapivideobuffer.c b/gst-libs/gst/vaapi/gstvaapivideobuffer.c
index 81176ffb..7d80e501 100644
--- a/gst-libs/gst/vaapi/gstvaapivideobuffer.c
+++ b/gst-libs/gst/vaapi/gstvaapivideobuffer.c
@@ -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);
diff --git a/gst-libs/gst/vaapi/gstvaapivideoconverter_glx.c b/gst-libs/gst/vaapi/gstvaapivideoconverter_glx.c
index 106b8ea8..0ea968fb 100644
--- a/gst-libs/gst/vaapi/gstvaapivideoconverter_glx.c
+++ b/gst-libs/gst/vaapi/gstvaapivideoconverter_glx.c
@@ -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);
}
diff --git a/gst-libs/gst/vaapi/gstvaapivideopool.c b/gst-libs/gst/vaapi/gstvaapivideopool.c
index e1064835..ea24befd 100644
--- a/gst-libs/gst/vaapi/gstvaapivideopool.c
+++ b/gst-libs/gst/vaapi/gstvaapivideopool.c
@@ -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