/* No lock necessary. This function is not multiple caller safe! */ static void memblock_make_local(pa_memblock *b) { pa_assert(b); pa_atomic_dec(&b->pool->stat.n_allocated_by_type[b->type]); if (b->length <= b->pool->block_size) { struct mempool_slot *slot; if ((slot = mempool_allocate_slot(b->pool))) { void *new_data; /* We can move it into a local pool, perfect! */ new_data = mempool_slot_data(slot); memcpy(new_data, pa_atomic_ptr_load(&b->data), b->length); pa_atomic_ptr_store(&b->data, new_data); b->type = PA_MEMBLOCK_POOL_EXTERNAL; b->read_only = false; goto finish; } } /* Humm, not enough space in the pool, so lets allocate the memory with malloc() */ b->per_type.user.free_cb = pa_xfree; pa_atomic_ptr_store(&b->data, pa_xmemdup(pa_atomic_ptr_load(&b->data), b->length)); b->type = PA_MEMBLOCK_USER; b->read_only = false; finish: pa_atomic_inc(&b->pool->stat.n_allocated_by_type[b->type]); pa_atomic_inc(&b->pool->stat.n_accumulated_by_type[b->type]); memblock_wait(b); }
pa_client_conf *pa_client_conf_new(void) { pa_client_conf *c = pa_xmemdup(&default_conf, sizeof(default_conf)); c->daemon_binary = pa_xstrdup(PA_BINARY); c->extra_arguments = pa_xstrdup("--log-target=syslog"); c->cookie_file = pa_xstrdup(PA_NATIVE_COOKIE_FILE); return c; }
pa_tagstruct *pa_tagstruct_copy(pa_tagstruct*t) { pa_tagstruct*tc; if (!(tc = pa_flist_pop(PA_STATIC_FLIST_GET(tagstructs)))) tc = pa_xnew(pa_tagstruct, 1); tc->data = pa_xmemdup(t->data, t->length); tc->allocated = t->length; tc->rindex = 0; tc->type = PA_TAGSTRUCT_DYNAMIC; return tc; }