mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-12-15 08:56:38 -05:00
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:
parent
34380ff02e
commit
b225fe1d54
2 changed files with 21 additions and 3 deletions
|
|
@ -89,7 +89,7 @@ struct support {
|
||||||
struct spa_interface i18n_iface;
|
struct spa_interface i18n_iface;
|
||||||
struct spa_support support[MAX_SUPPORT];
|
struct spa_support support[MAX_SUPPORT];
|
||||||
uint32_t n_support;
|
uint32_t n_support;
|
||||||
unsigned int initialized:1;
|
uint32_t init_count;
|
||||||
unsigned int in_valgrind:1;
|
unsigned int in_valgrind:1;
|
||||||
unsigned int no_color:1;
|
unsigned int no_color:1;
|
||||||
unsigned int no_config:1;
|
unsigned int no_config:1;
|
||||||
|
|
@ -592,7 +592,7 @@ void pw_init(int *argc, char **argv[])
|
||||||
char level[32];
|
char level[32];
|
||||||
|
|
||||||
pthread_mutex_lock(&init_lock);
|
pthread_mutex_lock(&init_lock);
|
||||||
if (support->initialized)
|
if (support->init_count > 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
pthread_mutex_lock(&support_lock);
|
pthread_mutex_lock(&support_lock);
|
||||||
|
|
@ -664,9 +664,9 @@ void pw_init(int *argc, char **argv[])
|
||||||
add_i18n(support);
|
add_i18n(support);
|
||||||
|
|
||||||
pw_log_info("version %s", pw_get_library_version());
|
pw_log_info("version %s", pw_get_library_version());
|
||||||
support->initialized = true;
|
|
||||||
pthread_mutex_unlock(&support_lock);
|
pthread_mutex_unlock(&support_lock);
|
||||||
done:
|
done:
|
||||||
|
support->init_count++;
|
||||||
pthread_mutex_unlock(&init_lock);
|
pthread_mutex_unlock(&init_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -678,6 +678,11 @@ void pw_deinit(void)
|
||||||
struct plugin *p;
|
struct plugin *p;
|
||||||
|
|
||||||
pthread_mutex_lock(&init_lock);
|
pthread_mutex_lock(&init_lock);
|
||||||
|
if (support->init_count == 0)
|
||||||
|
goto done;
|
||||||
|
if (--support->init_count > 0)
|
||||||
|
goto done;
|
||||||
|
|
||||||
pthread_mutex_lock(&support_lock);
|
pthread_mutex_lock(&support_lock);
|
||||||
pw_log_set(NULL);
|
pw_log_set(NULL);
|
||||||
spa_list_consume(p, ®istry->plugins, link) {
|
spa_list_consume(p, ®istry->plugins, link) {
|
||||||
|
|
@ -691,6 +696,7 @@ void pw_deinit(void)
|
||||||
free(support->i18n_domain);
|
free(support->i18n_domain);
|
||||||
spa_zero(global_support);
|
spa_zero(global_support);
|
||||||
pthread_mutex_unlock(&support_lock);
|
pthread_mutex_unlock(&support_lock);
|
||||||
|
done:
|
||||||
pthread_mutex_unlock(&init_lock);
|
pthread_mutex_unlock(&init_lock);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,9 +49,21 @@ PWTEST(library_version)
|
||||||
return PWTEST_PASS;
|
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_SUITE(properties)
|
||||||
{
|
{
|
||||||
pwtest_add(library_version, PWTEST_NOARG);
|
pwtest_add(library_version, PWTEST_NOARG);
|
||||||
|
pwtest_add(init_deinit, PWTEST_NOARG);
|
||||||
|
|
||||||
return PWTEST_PASS;
|
return PWTEST_PASS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue