[pulseaudio-discuss] [PATCH 08/12] core: Add a second rw mempool

David Henningsson david.henningsson at canonical.com
Fri May 30 04:59:27 PDT 2014


To keep the data and the ringbuffer separate, let's add another
mempool just for the ringbuffer(s). That way, the client can open
the ringbuffer shm file in rw mode and keep the data in ro mode.

Signed-off-by: David Henningsson <david.henningsson at canonical.com>
---
 src/pulsecore/core.c | 14 ++++++++++++--
 src/pulsecore/core.h |  5 ++++-
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/pulsecore/core.c b/src/pulsecore/core.c
index e6f2dfc..b0f2314 100644
--- a/src/pulsecore/core.c
+++ b/src/pulsecore/core.c
@@ -127,6 +127,11 @@ pa_core* pa_core_new(pa_mainloop_api *m, bool shared, size_t shm_size) {
     c->mempool = pool;
     pa_silence_cache_init(&c->silence_cache);
 
+    if (shared && !(c->rw_mempool = pa_mempool_new(shared, shm_size)))
+        pa_log_warn("failed to allocate shared writable memory pool.");
+    if (c->rw_mempool)
+        pa_mempool_set_is_remote_writable(c->rw_mempool, true);
+
     c->exit_event = NULL;
 
     c->exit_idle_time = -1;
@@ -208,6 +213,8 @@ static void core_free(pa_object *o) {
     pa_assert(!c->default_sink);
 
     pa_silence_cache_done(&c->silence_cache);
+    if (c->rw_mempool)
+        pa_mempool_free(c->rw_mempool);
     pa_mempool_free(c->mempool);
 
     for (j = 0; j < PA_CORE_HOOK_MAX; j++)
@@ -254,7 +261,6 @@ void pa_core_maybe_vacuum(pa_core *c) {
 
     if (pa_idxset_isempty(c->sink_inputs) && pa_idxset_isempty(c->source_outputs)) {
         pa_log_debug("Hmm, no streams around, trying to vacuum.");
-        pa_mempool_vacuum(c->mempool);
     } else {
         pa_sink *si;
         pa_source *so;
@@ -271,8 +277,12 @@ void pa_core_maybe_vacuum(pa_core *c) {
                 return;
 
         pa_log_info("All sinks and sources are suspended, vacuuming memory");
-        pa_mempool_vacuum(c->mempool);
     }
+
+    pa_mempool_vacuum(c->mempool);
+
+    if (c->rw_mempool)
+        pa_mempool_vacuum(c->rw_mempool);
 }
 
 pa_time_event* pa_core_rttime_new(pa_core *c, pa_usec_t usec, pa_time_event_cb_t cb, void *userdata) {
diff --git a/src/pulsecore/core.h b/src/pulsecore/core.h
index b443ce4..1f9df73 100644
--- a/src/pulsecore/core.h
+++ b/src/pulsecore/core.h
@@ -170,7 +170,10 @@ struct pa_core {
     PA_LLIST_HEAD(pa_subscription_event, subscription_event_queue);
     pa_subscription_event *subscription_event_last;
 
-    pa_mempool *mempool;
+    /* The mempool is used for data we write to, it's readonly for the client.
+       The rw_mempool is used for data writable by both server and client (and
+       can be NULL in some cases). */
+    pa_mempool *mempool, *rw_mempool;
     pa_silence_cache silence_cache;
 
     pa_time_event *exit_event;
-- 
1.9.1



More information about the pulseaudio-discuss mailing list