get rid of nonsensical late initialization of namereg/scache and things

This commit is contained in:
Lennart Poettering 2009-01-29 16:25:29 +01:00
parent 4a06af6081
commit 746dc2ac19
9 changed files with 41 additions and 102 deletions

View file

@ -120,9 +120,6 @@ static pa_scache_entry* scache_add_item(pa_core *c, const char *name) {
e->core = c;
e->proplist = pa_proplist_new();
if (!c->scache)
c->scache = pa_idxset_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
pa_idxset_put(c->scache, e, &e->index);
pa_subscription_post(c, PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE|PA_SUBSCRIPTION_EVENT_NEW, e->index);
@ -287,23 +284,18 @@ int pa_scache_remove_item(pa_core *c, const char *name) {
return 0;
}
static void free_cb(void *p, void *userdata) {
pa_scache_entry *e = p;
pa_assert(e);
void pa_scache_free_all(pa_core *c) {
pa_scache_entry *e;
free_entry(e);
}
void pa_scache_free(pa_core *c) {
pa_assert(c);
if (c->scache) {
pa_idxset_free(c->scache, free_cb, NULL);
c->scache = NULL;
}
while ((e = pa_idxset_steal_first(c->scache, NULL)))
free_entry(e);
if (c->scache_auto_unload_event)
if (c->scache_auto_unload_event) {
c->mainloop->time_free(c->scache_auto_unload_event);
c->scache_auto_unload_event = NULL;
}
}
int pa_scache_play_item(pa_core *c, const char *name, pa_sink *sink, pa_volume_t volume, pa_proplist *p, uint32_t *sink_input_idx) {

View file

@ -58,7 +58,7 @@ int pa_scache_add_directory_lazy(pa_core *c, const char *pathname);
int pa_scache_remove_item(pa_core *c, const char *name);
int pa_scache_play_item(pa_core *c, const char *name, pa_sink *sink, pa_volume_t volume, pa_proplist *p, uint32_t *sink_input_idx);
int pa_scache_play_item_by_name(pa_core *c, const char *name, const char*sink_name, pa_volume_t volume, pa_proplist *p, uint32_t *sink_input_idx);
void pa_scache_free(pa_core *c);
void pa_scache_free_all(pa_core *c);
const char *pa_scache_get_name_by_id(pa_core *c, uint32_t id);
uint32_t pa_scache_get_id_by_name(pa_core *c, const char *name);

View file

@ -92,21 +92,22 @@ pa_core* pa_core_new(pa_mainloop_api *m, pa_bool_t shared, size_t shm_size) {
c->state = PA_CORE_STARTUP;
c->mainloop = m;
c->clients = pa_idxset_new(NULL, NULL);
c->cards = pa_idxset_new(NULL, NULL);
c->sinks = pa_idxset_new(NULL, NULL);
c->sources = pa_idxset_new(NULL, NULL);
c->source_outputs = pa_idxset_new(NULL, NULL);
c->sink_inputs = pa_idxset_new(NULL, NULL);
c->cards = pa_idxset_new(NULL, NULL);
c->source_outputs = pa_idxset_new(NULL, NULL);
c->modules = pa_idxset_new(NULL, NULL);
c->scache = pa_idxset_new(NULL, NULL);
c->namereg = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
c->shared = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
c->default_source = NULL;
c->default_sink = NULL;
c->modules = NULL;
c->namereg = NULL;
c->scache = NULL;
c->running_as_daemon = FALSE;
c->default_sample_spec.format = PA_SAMPLE_S16NE;
c->default_sample_spec.rate = 44100;
c->default_sample_spec.channels = 2;
@ -128,22 +129,20 @@ pa_core* pa_core_new(pa_mainloop_api *m, pa_bool_t shared, size_t shm_size) {
c->exit_idle_time = -1;
c->scache_idle_time = 20;
c->flat_volumes = TRUE;
c->resample_method = PA_RESAMPLER_SPEEX_FLOAT_BASE + 3;
c->disallow_module_loading = FALSE;
c->disallow_exit = FALSE;
c->running_as_daemon = FALSE;
c->realtime_scheduling = FALSE;
c->realtime_priority = 5;
c->disable_remixing = FALSE;
c->disable_lfe_remixing = FALSE;
c->resample_method = PA_RESAMPLER_SPEEX_FLOAT_BASE + 3;
for (j = 0; j < PA_CORE_HOOK_MAX; j++)
pa_hook_init(&c->hooks[j], c);
pa_shared_init(c);
pa_random(&c->cookie, sizeof(c->cookie));
#ifdef SIGPIPE
@ -165,7 +164,13 @@ static void core_free(pa_object *o) {
c->state = PA_CORE_SHUTDOWN;
pa_module_unload_all(c);
pa_assert(!c->modules);
pa_scache_free_all(c);
pa_assert(pa_idxset_isempty(c->scache));
pa_idxset_free(c->scache, NULL, NULL);
pa_assert(pa_idxset_isempty(c->modules));
pa_idxset_free(c->modules, NULL, NULL);
pa_assert(pa_idxset_isempty(c->clients));
pa_idxset_free(c->clients, NULL, NULL);
@ -185,8 +190,12 @@ static void core_free(pa_object *o) {
pa_assert(pa_idxset_isempty(c->sink_inputs));
pa_idxset_free(c->sink_inputs, NULL, NULL);
pa_scache_free(c);
pa_namereg_free(c);
pa_assert(pa_hashmap_isempty(c->namereg));
pa_hashmap_free(c->namereg, NULL, NULL);
pa_assert(pa_hashmap_isempty(c->shared));
pa_hashmap_free(c->shared, NULL, NULL);
pa_subscription_free_all(c);
if (c->exit_event)
@ -198,8 +207,6 @@ static void core_free(pa_object *o) {
pa_silence_cache_done(&c->silence_cache);
pa_mempool_free(c->mempool);
pa_shared_cleanup(c);
for (j = 0; j < PA_CORE_HOOK_MAX; j++)
pa_hook_done(&c->hooks[j]);

View file

@ -112,7 +112,7 @@ struct pa_core {
/* Some hashmaps for all sorts of entities */
pa_hashmap *namereg, *shared;
/* The name of the default sink/source */
/* The default sink/source */
pa_source *default_source;
pa_sink *default_sink;
@ -129,13 +129,12 @@ struct pa_core {
pa_mempool *mempool;
pa_silence_cache silence_cache;
int exit_idle_time, scache_idle_time;
pa_bool_t flat_volumes;
pa_time_event *exit_event;
pa_time_event *scache_auto_unload_event;
int exit_idle_time, scache_idle_time;
pa_bool_t flat_volumes:1;
pa_bool_t disallow_module_loading:1;
pa_bool_t disallow_exit:1;
pa_bool_t running_as_daemon:1;

View file

@ -75,7 +75,7 @@ pa_module* pa_module_load(pa_core *c, const char *name, const char *argument) {
m->load_once = load_once();
if (m->load_once && c->modules) {
if (m->load_once) {
pa_module *i;
uint32_t idx;
/* OK, the module only wants to be loaded once, let's make sure it is */
@ -105,9 +105,6 @@ pa_module* pa_module_load(pa_core *c, const char *name, const char *argument) {
goto fail;
}
if (!c->modules)
c->modules = pa_idxset_new(NULL, NULL);
pa_assert_se(pa_idxset_put(c->modules, m, &m->index) >= 0);
pa_assert(m->index != PA_IDXSET_INVALID);
@ -200,18 +197,12 @@ void pa_module_unload_by_index(pa_core *c, uint32_t idx, pa_bool_t force) {
}
void pa_module_unload_all(pa_core *c) {
pa_assert(c);
if (c->modules) {
pa_module *m;
pa_assert(c);
while ((m = pa_idxset_steal_first(c->modules, NULL)))
pa_module_free(m);
pa_idxset_free(c->modules, NULL, NULL);
c->modules = NULL;
}
if (c->module_defer_unload_event) {
c->mainloop->defer_free(c->module_defer_unload_event);
c->module_defer_unload_event = NULL;
@ -226,9 +217,6 @@ static void defer_cb(pa_mainloop_api*api, pa_defer_event *e, void *userdata) {
pa_core_assert_ref(c);
api->defer_enable(e, 0);
if (!c->modules)
return;
while ((m = pa_idxset_iterate(c->modules, &state, NULL)))
if (m->unload_requested)
pa_module_unload(c, m, TRUE);

View file

@ -87,16 +87,6 @@ char* pa_namereg_make_valid_name(const char *name) {
return n;
}
void pa_namereg_free(pa_core *c) {
pa_assert(c);
if (!c->namereg)
return;
pa_assert(pa_hashmap_size(c->namereg) == 0);
pa_hashmap_free(c->namereg, NULL, NULL);
}
const char *pa_namereg_register(pa_core *c, const char *name, pa_namereg_type_t type, void *data, pa_bool_t fail) {
struct namereg_entry *e;
char *n = NULL;
@ -118,9 +108,6 @@ const char *pa_namereg_register(pa_core *c, const char *name, pa_namereg_type_t
return NULL;
}
if (!c->namereg)
c->namereg = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
if ((e = pa_hashmap_get(c->namereg, name)) && fail) {
pa_xfree(n);
return NULL;
@ -210,7 +197,7 @@ void* pa_namereg_get(pa_core *c, const char *name, pa_namereg_type_t type) {
if (*name == '@' || !name || !pa_namereg_is_valid_name(name))
return NULL;
if (c->namereg && (e = pa_hashmap_get(c->namereg, name)))
if ((e = pa_hashmap_get(c->namereg, name)))
if (e->type == type)
return e->data;

View file

@ -34,8 +34,6 @@ typedef enum pa_namereg_type {
PA_NAMEREG_CARD
} pa_namereg_type_t;
void pa_namereg_free(pa_core *c);
const char *pa_namereg_register(pa_core *c, const char *name, pa_namereg_type_t type, void *data, pa_bool_t fail);
void pa_namereg_unregister(pa_core *c, const char *name);
void* pa_namereg_get(pa_core *c, const char *name, pa_namereg_type_t type);

View file

@ -99,32 +99,6 @@ int pa_shared_remove(pa_core *c, const char *name) {
return 0;
}
void pa_shared_init(pa_core *c) {
pa_assert(c);
c->shared = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
}
void pa_shared_cleanup(pa_core *c) {
pa_assert(c);
if (!c->shared)
return;
if (!pa_hashmap_isempty(c->shared)) {
pa_strbuf *s = pa_strbuf_new();
pa_shared_dump(c, s);
pa_log_debug("%s", pa_strbuf_tostring(s));
pa_strbuf_free(s);
pa_assert(pa_hashmap_isempty(c->shared));
}
pa_hashmap_free(c->shared, NULL, NULL);
c->shared = NULL;
}
void pa_shared_dump(pa_core *c, pa_strbuf *s) {
void *state = NULL;
pa_shared *p;

View file

@ -49,12 +49,6 @@ int pa_shared_remove(pa_core *c, const char *name);
/* A combination of pa_shared_remove() and pa_shared_set() */
int pa_shared_replace(pa_core *c, const char *name, void *data);
/* Free all memory used by the shared property system */
void pa_shared_cleanup(pa_core *c);
/* Initialize the shared property system */
void pa_shared_init(pa_core *c);
/* Dump the current set of shared properties */
void pa_shared_dump(pa_core *c, pa_strbuf *s);