diff options
author | David Henningsson <david.henningsson@canonical.com> | 2014-04-25 14:20:57 +0200 |
---|---|---|
committer | David Henningsson <david.henningsson@canonical.com> | 2014-06-27 14:16:33 +0200 |
commit | b06e61652533201f0b58ed339d4435099d180a36 (patch) | |
tree | f3dd4188f226fc7b5e8a8d9366f6d72903badf5d | |
parent | 073128fbc878d0434cc89d73fd80db3d97f62764 (diff) |
core: Add a second rw mempool
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@canonical.com>
-rw-r--r-- | src/pulsecore/core.c | 14 | ||||
-rw-r--r-- | 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 e6f2dfcba..b0f231498 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 b443ce4a8..1f9df73e3 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; |