diff options
author | Stian Selnes <stian@pexip.com> | 2015-08-05 10:07:50 +0200 |
---|---|---|
committer | Tim-Philipp Müller <tim@centricular.com> | 2015-09-07 11:31:33 +0100 |
commit | ff9a78196c032588d75b99f6dfb74817bde196c2 (patch) | |
tree | 01c1225b3099eb530f9674e66b6e3106843f4a1c /libs | |
parent | 615e5b01c6426e3e8cdb09bb56c962f3893bda6f (diff) |
harness: Fix race for gst_harness_element_ref
In order for gst_harness_new_full to be MT-safe the increase and
decrease of HARNESS_REF must be MT-safe. This allows for creating
multiple harnesses from different threads wrapping the same element.
https://bugzilla.gnome.org/show_bug.cgi?id=754661
Diffstat (limited to 'libs')
-rw-r--r-- | libs/gst/check/gstharness.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/libs/gst/check/gstharness.c b/libs/gst/check/gstharness.c index cfaa5861a..6a8cde3c8 100644 --- a/libs/gst/check/gstharness.c +++ b/libs/gst/check/gstharness.c @@ -433,7 +433,10 @@ gst_harness_src_query (GstPad * pad, GstObject * parent, GstQuery * query) static void gst_harness_element_ref (GstHarness * h) { - guint *data = g_object_get_data (G_OBJECT (h->element), HARNESS_REF); + guint *data; + + GST_OBJECT_LOCK (h->element); + data = g_object_get_data (G_OBJECT (h->element), HARNESS_REF); if (data == NULL) { data = g_new0 (guint, 1); *data = 1; @@ -441,15 +444,23 @@ gst_harness_element_ref (GstHarness * h) } else { (*data)++; } + GST_OBJECT_UNLOCK (h->element); } static guint gst_harness_element_unref (GstHarness * h) { - guint *data = g_object_get_data (G_OBJECT (h->element), HARNESS_REF); + guint *data; + guint ret; + + GST_OBJECT_LOCK (h->element); + data = g_object_get_data (G_OBJECT (h->element), HARNESS_REF); g_assert (data != NULL); (*data)--; - return *data; + ret = *data; + GST_OBJECT_UNLOCK (h->element); + + return ret; } static void |