#include <pulsecore/log.h>
#include <pulsecore/hashmap.h>
#include <pulsecore/semaphore.h>
+#include <pulsecore/mutex.h>
#include <pulsecore/macro.h>
+#include <pulsecore/refcnt.h>
+#include <pulsecore/llist.h>
#include <pulsecore/flist.h>
#include <pulsecore/core-util.h>
#include <pulsecore/memtrap.h>
pa_free_cb_t free_cb;
} user;
- struct {
+ struct {
uint32_t id;
pa_memimport_segment *segment;
} imported;
/* If -1 is passed as length we choose the size for the caller. */
if (length == (size_t) -1)
- length = p->block_size - PA_ALIGN(sizeof(pa_memblock));
+ length = pa_mempool_block_size_max(p);
b = pa_xmalloc(PA_ALIGN(sizeof(pa_memblock)) + length);
PA_REFCNT_INIT(b);
slot = (struct mempool_slot*) ((uint8_t*) p->memory.ptr + (p->block_size * (size_t) idx));
if (!slot) {
- if (pa_log_ratelimit())
+ if (pa_log_ratelimit(PA_LOG_DEBUG))
pa_log_debug("Pool full");
pa_atomic_inc(&p->stat.n_pool_full);
return NULL;
return pa_atomic_ptr_load(&b->data);
}
+/* No lock necessary */
+void *pa_memblock_acquire_chunk(const pa_memchunk *c) {
+ pa_assert(c);
+
+ return (uint8_t *) pa_memblock_acquire(c->memblock) + c->index;
+}
+
/* No lock necessary, in corner cases locks by its own */
void pa_memblock_release(pa_memblock *b) {
int r;
case PA_MEMBLOCK_APPENDED:
- /* We could attached it unused_memblocks, but that would
- * probably waste some considerable memory */
+ /* We could attach it to unused_memblocks, but that would
+ * probably waste some considerable amount of memory */
pa_xfree(b);
break;
pa_mutex_lock(import->mutex);
- pa_assert_se(pa_hashmap_remove(
- import->blocks,
- PA_UINT32_TO_PTR(b->per_type.imported.id)));
+ pa_assert_se(pa_hashmap_remove(import->blocks, PA_UINT32_TO_PTR(b->per_type.imported.id)));
pa_assert(segment->n_blocks >= 1);
if (-- segment->n_blocks <= 0)
pa_mutex_lock(import->mutex);
- pa_assert_se(pa_hashmap_remove(
- import->blocks,
- PA_UINT32_TO_PTR(b->per_type.imported.id)));
+ pa_assert_se(pa_hashmap_remove(import->blocks, PA_UINT32_TO_PTR(b->per_type.imported.id)));
memblock_make_local(b);
p = pa_xnew(pa_mempool, 1);
- p->mutex = pa_mutex_new(TRUE, TRUE);
- p->semaphore = pa_semaphore_new(0);
-
p->block_size = PA_PAGE_ALIGN(PA_MEMPOOL_SLOT_SIZE);
if (p->block_size < PA_PAGE_SIZE)
p->block_size = PA_PAGE_SIZE;
PA_LLIST_HEAD_INIT(pa_memimport, p->imports);
PA_LLIST_HEAD_INIT(pa_memexport, p->exports);
+ p->mutex = pa_mutex_new(TRUE, TRUE);
+ p->semaphore = pa_semaphore_new(0);
+
p->free_slots = pa_flist_new(p->n_blocks);
return p;
return !!p->memory.shared;
}
-/* For recieving blocks from other nodes */
+/* For receiving blocks from other nodes */
pa_memimport* pa_memimport_new(pa_mempool *p, pa_memimport_release_cb_t cb, void *userdata) {
pa_memimport *i;