]> code.delx.au - pulseaudio/commitdiff
get rid of nonsensical late initialization of namereg/scache and things
authorLennart Poettering <lennart@poettering.net>
Thu, 29 Jan 2009 15:25:29 +0000 (16:25 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 29 Jan 2009 15:25:29 +0000 (16:25 +0100)
src/pulsecore/core-scache.c
src/pulsecore/core-scache.h
src/pulsecore/core.c
src/pulsecore/core.h
src/pulsecore/module.c
src/pulsecore/namereg.c
src/pulsecore/namereg.h
src/pulsecore/shared.c
src/pulsecore/shared.h

index 6d2ae932f5e7dcd63773cf52b2968d99dac59054..e5489415ff6c778bf02d49f91c7c68c9bb67a380 100644 (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);
-
-    free_entry(e);
-}
+void pa_scache_free_all(pa_core *c) {
+    pa_scache_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) {
index a75f8aca66089f79fe0e60b325b862f50e4931d4..1fe3c309729982ef037c61c0aa31737a82f5ec2d 100644 (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);
index 689fc8f8a7f02674bb672a0c8bf1c89a2259b94b..5fd2bdfb4359cc90056f819efb2d9154ef9dc211 100644 (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->flat_volumes = TRUE;
     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]);
 
index b349c6fc924e5f86e82bfedc2ab241439decc3c7..2b8f819b1abbd93236426f5f2a346e8b3dd20951 100644 (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;
index d470bb0bbff669d749bfa4df1982225f12a224cd..1eb70c8e241f3a71b1b13ec6068e0c06012c4552 100644 (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,17 +197,11 @@ 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_module *m;
     pa_assert(c);
 
-    if (c->modules) {
-        pa_module *m;
-
-        while ((m = pa_idxset_steal_first(c->modules, NULL)))
-            pa_module_free(m);
-
-        pa_idxset_free(c->modules, NULL, NULL);
-        c->modules = NULL;
-    }
+    while ((m = pa_idxset_steal_first(c->modules, NULL)))
+        pa_module_free(m);
 
     if (c->module_defer_unload_event) {
         c->mainloop->defer_free(c->module_defer_unload_event);
@@ -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);
index f3d5a8f8355058dc892e96ed1a1f227f478dc41f..ac456ac7ebed5db02574dca771d8d5f2a5d7840a 100644 (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;
 
index b91dd52d5d8ffe0a82b3df2dd62f9efaa124e5b5..ff99525e2005ae0d833004b7b5342387255762e6 100644 (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);
index d6e42dd87e31882fab9b2ca04f4b62470bfd216f..9485dc3332b37f9df2796446d4d22f7cb9002585 100644 (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;
index dd3f94e214ca738f6c39945fb4d12ac8100b67d7..f6f8d3cf0f3c17801b6b2c1287ba27c66a96abcf 100644 (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);