pipewire: improve pw_init/pw_deinit

Keep a counter for the amount of times pw_init() was called and
only clear everything when pw_deinit() was called an equal amount of
times.
Also ensure that pw_init() can be called again after pw_deinit().

Fixes #2238
This commit is contained in:
Wim Taymans 2022-03-26 21:20:07 +01:00
parent 34380ff02e
commit b225fe1d54
2 changed files with 21 additions and 3 deletions

View file

@ -89,7 +89,7 @@ struct support {
struct spa_interface i18n_iface;
struct spa_support support[MAX_SUPPORT];
uint32_t n_support;
unsigned int initialized:1;
uint32_t init_count;
unsigned int in_valgrind:1;
unsigned int no_color:1;
unsigned int no_config:1;
@ -592,7 +592,7 @@ void pw_init(int *argc, char **argv[])
char level[32];
pthread_mutex_lock(&init_lock);
if (support->initialized)
if (support->init_count > 0)
goto done;
pthread_mutex_lock(&support_lock);
@ -664,9 +664,9 @@ void pw_init(int *argc, char **argv[])
add_i18n(support);
pw_log_info("version %s", pw_get_library_version());
support->initialized = true;
pthread_mutex_unlock(&support_lock);
done:
support->init_count++;
pthread_mutex_unlock(&init_lock);
}
@ -678,6 +678,11 @@ void pw_deinit(void)
struct plugin *p;
pthread_mutex_lock(&init_lock);
if (support->init_count == 0)
goto done;
if (--support->init_count > 0)
goto done;
pthread_mutex_lock(&support_lock);
pw_log_set(NULL);
spa_list_consume(p, &registry->plugins, link) {
@ -691,6 +696,7 @@ void pw_deinit(void)
free(support->i18n_domain);
spa_zero(global_support);
pthread_mutex_unlock(&support_lock);
done:
pthread_mutex_unlock(&init_lock);
}

View file

@ -49,9 +49,21 @@ PWTEST(library_version)
return PWTEST_PASS;
}
PWTEST(init_deinit)
{
pw_init(0, NULL);
pw_deinit();
pw_init(0, NULL);
pw_init(0, NULL);
pw_deinit();
pw_deinit();
return PWTEST_PASS;
}
PWTEST_SUITE(properties)
{
pwtest_add(library_version, PWTEST_NOARG);
pwtest_add(init_deinit, PWTEST_NOARG);
return PWTEST_PASS;
}