mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-25 17:50:36 +00:00
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>
This commit is contained in:
parent
2e0a21c9c2
commit
d7d12f6aaa
2 changed files with 19 additions and 11 deletions
18
gst/gst.c
18
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;
|
||||
g_mutex_lock (&init_lock);
|
||||
|
||||
GST_INFO ("deinitializing GStreamer");
|
||||
|
||||
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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue