Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/GStreamer/gstreamer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Boxer <aaron.boxer@collabora.com>2019-08-12 02:13:57 +0300
committerOlivier CrĂȘte <olivier.crete@ocrete.ca>2021-03-25 00:14:22 +0300
commitd7d12f6aaad3319af5d0b029b61311a6f36db44f (patch)
treefa40f75bb0b39daaf9ed47d9b16316c6607b0089
parent2e0a21c9c209ce0549434bdb97862f993c887fa7 (diff)
gst: enforce gst_deinit one call per process
unit tests do not need to call deinit as it is already called in exit handler Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/236>
-rw-r--r--gst/gst.c18
-rw-r--r--tests/check/gst/gst.c12
2 files changed, 19 insertions, 11 deletions
diff --git a/gst/gst.c b/gst/gst.c
index 7a26d87683..6ea42e0b32 100644
--- a/gst/gst.c
+++ b/gst/gst.c
@@ -131,6 +131,7 @@
static gboolean gst_initialized = FALSE;
static gboolean gst_deinitialized = FALSE;
+static GMutex init_lock;
GstClockTime _priv_gst_start_time;
@@ -410,7 +411,6 @@ gst_get_main_executable_path (void)
gboolean
gst_init_check (int *argc, char **argv[], GError ** error)
{
- static GMutex init_lock;
#ifndef GST_DISABLE_OPTION_PARSING
GOptionGroup *group;
GOptionContext *ctx;
@@ -1109,15 +1109,18 @@ gst_deinit (void)
GstBinClass *bin_class;
GstClock *clock;
- if (!gst_initialized)
- return;
-
- GST_INFO ("deinitializing GStreamer");
+ g_mutex_lock (&init_lock);
- if (gst_deinitialized) {
- GST_DEBUG ("already deinitialized");
+ if (!gst_initialized) {
+ g_mutex_unlock (&init_lock);
return;
}
+ if (gst_deinitialized) {
+ /* tell the user how naughty they've been */
+ g_error ("GStreamer should not be deinitialized a second time.");
+ }
+
+ GST_INFO ("deinitializing GStreamer");
g_thread_pool_set_max_unused_threads (0);
bin_class = (GstBinClass *) g_type_class_peek (gst_bin_get_type ());
if (bin_class && bin_class->pool != NULL) {
@@ -1262,6 +1265,7 @@ gst_deinit (void)
gst_deinitialized = TRUE;
GST_INFO ("deinitialized GStreamer");
+ g_mutex_unlock (&init_lock);
/* Doing this as the very last step to allow the above GST_INFO() to work
* correctly. It's of course making the above statement a lie: for a short
diff --git a/tests/check/gst/gst.c b/tests/check/gst/gst.c
index fc8276381e..c8208fba69 100644
--- a/tests/check/gst/gst.c
+++ b/tests/check/gst/gst.c
@@ -39,7 +39,7 @@ GST_START_TEST (test_deinit)
{
gst_init (NULL, NULL);
- gst_deinit ();
+ /* gst_deinit will be called by test exit handler */
}
GST_END_TEST;
@@ -53,7 +53,7 @@ GST_START_TEST (test_deinit_sysclock)
clock = gst_system_clock_obtain ();
gst_object_unref (clock);
- gst_deinit ();
+ /* gst_deinit will be called by test exit handler */
}
GST_END_TEST;
@@ -100,15 +100,19 @@ gst_suite (void)
{
Suite *s = suite_create ("Gst");
TCase *tc_chain = tcase_create ("gst tests");
+ const char *ck_fork = g_getenv ("CK_FORK");
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, test_init);
tcase_add_test (tc_chain, test_new_pipeline);
tcase_add_test (tc_chain, test_new_fakesrc);
tcase_add_test (tc_chain, test_version);
- /* run these last so the others don't fail if CK_FORK=no is being used */
+ /* run these last so the others don't fail if CK_FORK=no is being used.
+ * only run single test for deinitialization if CK_FORK=no, so system exit
+ * will make the single deinit call */
tcase_add_test (tc_chain, test_deinit_sysclock);
- tcase_add_test (tc_chain, test_deinit);
+ if (!ck_fork || (strcmp (ck_fork, "no") != 0))
+ tcase_add_test (tc_chain, test_deinit);
return s;
}