summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathieu Duponchelle <mathieu.duponchelle@collabora.com>2014-09-30 09:11:58 +0200
committerMathieu Duponchelle <mathieu.duponchelle@opencreed.com>2014-09-30 11:42:42 +0200
commit855f14145348bce32f38725a100c69b375466274 (patch)
tree73f600d45b3f864f3e5a01de9282f41cb865dd9e
parente7315aa78e0fad0a1a9d7b3acfbc1989a035bb9f (diff)
gst-validate-runner: Add locking for the reports list.
-rw-r--r--validate/gst/validate/gst-validate-runner.c24
-rw-r--r--validate/gst/validate/gst-validate-runner.h15
2 files changed, 35 insertions, 4 deletions
diff --git a/validate/gst/validate/gst-validate-runner.c b/validate/gst/validate/gst-validate-runner.c
index 88bda2b..8eec688 100644
--- a/validate/gst/validate/gst-validate-runner.c
+++ b/validate/gst/validate/gst-validate-runner.c
@@ -77,6 +77,8 @@ gst_validate_runner_dispose (GObject * object)
g_slist_free_full (runner->reports,
(GDestroyNotify) gst_validate_report_unref);
+ g_mutex_clear (&runner->mutex);
+
G_OBJECT_CLASS (parent_class)->dispose (object);
}
@@ -100,6 +102,7 @@ gst_validate_runner_init (GstValidateRunner * runner)
{
runner->setup = FALSE;
runner->max_printed_level = GST_VALIDATE_REPORT_LEVEL_NUM_ENTRIES;
+ g_mutex_init (&runner->mutex);
}
/**
@@ -119,7 +122,9 @@ void
gst_validate_runner_add_report (GstValidateRunner * runner,
GstValidateReport * report)
{
+ GST_VALIDATE_RUNNER_LOCK (runner);
runner->reports = g_slist_prepend (runner->reports, report);
+ GST_VALIDATE_RUNNER_UNLOCK (runner);
g_signal_emit (runner, _signals[REPORT_ADDED_SIGNAL], 0, report);
}
@@ -135,16 +140,27 @@ gst_validate_runner_add_report (GstValidateRunner * runner,
guint
gst_validate_runner_get_reports_count (GstValidateRunner * runner)
{
+ guint l;
+
g_return_val_if_fail (runner != NULL, 0);
- return g_slist_length (runner->reports);
+
+ GST_VALIDATE_RUNNER_LOCK (runner);
+ l = g_slist_length (runner->reports);
+ GST_VALIDATE_RUNNER_UNLOCK (runner);
+
+ return l;
}
GSList *
gst_validate_runner_get_reports (GstValidateRunner * runner)
{
- /* TODO should we need locking or put in the docs to always call this
- * after pipeline ends? */
- return g_slist_reverse (runner->reports);
+ GSList *ret;
+
+ GST_VALIDATE_RUNNER_LOCK (runner);
+ ret = g_slist_reverse (runner->reports);
+ GST_VALIDATE_RUNNER_UNLOCK (runner);
+
+ return ret;
}
/**
diff --git a/validate/gst/validate/gst-validate-runner.h b/validate/gst/validate/gst-validate-runner.h
index 76da09b..f544a95 100644
--- a/validate/gst/validate/gst-validate-runner.h
+++ b/validate/gst/validate/gst-validate-runner.h
@@ -41,6 +41,20 @@ G_BEGIN_DECLS
#define GST_VALIDATE_RUNNER_CAST(obj) ((GstValidateRunner*)(obj))
#define GST_VALIDATE_RUNNER_CLASS_CAST(klass) ((GstValidateRunnerClass*)(klass))
+#define GST_VALIDATE_RUNNER_LOCK(r) \
+ G_STMT_START { \
+ GST_LOG_OBJECT (r, "About to lock %p", &GST_VALIDATE_RUNNER_CAST(r)->mutex); \
+ (g_mutex_lock (&GST_VALIDATE_RUNNER_CAST(r)->mutex)); \
+ GST_LOG_OBJECT (r, "Acquired lock %p", &GST_VALIDATE_RUNNER_CAST(r)->mutex); \
+ } G_STMT_END
+
+#define GST_VALIDATE_RUNNER_UNLOCK(r) \
+ G_STMT_START { \
+ GST_LOG_OBJECT (r, "About to unlock %p", &GST_VALIDATE_RUNNER_CAST(r)->mutex); \
+ (g_mutex_unlock (&GST_VALIDATE_RUNNER_CAST(r)->mutex)); \
+ GST_LOG_OBJECT (r, "Released lock %p", &GST_VALIDATE_RUNNER_CAST(r)->mutex); \
+ } G_STMT_END
+
/* TODO hide this to be opaque? */
/**
* GstValidateRunner:
@@ -54,6 +68,7 @@ struct _GstValidateRunner {
gboolean setup;
guint max_printed_level;
+ GMutex mutex;
/*< private >*/
GSList *reports;