diff options
author | Wim Taymans <wtaymans@redhat.com> | 2020-04-22 11:30:53 +0200 |
---|---|---|
committer | Wim Taymans <wtaymans@redhat.com> | 2020-04-22 11:30:53 +0200 |
commit | 8ab67c5fa0a941c7d6e1edd58538baa024f7f9dd (patch) | |
tree | de93fe2398f5f7a132ac1eeeea9b61dd29aa553f /src | |
parent | d68e7ed58abc6c3d4104f4652783a5a26f08a7b1 (diff) |
mem: implement remove_id
Rename (the non-exported symbol) _unref_id -> _remove_id and make it
remove the id from the map of known ids. This way, the server can send
the remove_mem and reuse the id for new memory before all references
are gone. Fixes "invalid mem id X, expected Y" errors.
Diffstat (limited to 'src')
-rw-r--r-- | src/pipewire/core.c | 2 | ||||
-rw-r--r-- | src/pipewire/mem.c | 9 | ||||
-rw-r--r-- | src/pipewire/mem.h | 4 |
3 files changed, 9 insertions, 6 deletions
diff --git a/src/pipewire/core.c b/src/pipewire/core.c index 9e7cef65..637a84a5 100644 --- a/src/pipewire/core.c +++ b/src/pipewire/core.c @@ -115,7 +115,7 @@ static void core_event_remove_mem(void *data, uint32_t id) { struct pw_core *this = data; pw_log_debug(NAME" %p: remove mem %u", this, id); - pw_mempool_unref_id(this->pool, id); + pw_mempool_remove_id(this->pool, id); } static const struct pw_core_events core_events = { diff --git a/src/pipewire/mem.c b/src/pipewire/mem.c index 30bb9158..50ee6b40 100644 --- a/src/pipewire/mem.c +++ b/src/pipewire/mem.c @@ -623,8 +623,7 @@ struct pw_memmap * pw_mempool_import_map(struct pw_mempool *pool, return map; } - -int pw_mempool_unref_id(struct pw_mempool *pool, uint32_t id) +int pw_mempool_remove_id(struct pw_mempool *pool, uint32_t id) { struct mempool *impl = SPA_CONTAINER_OF(pool, struct mempool, this); struct memblock *b; @@ -636,7 +635,10 @@ int pw_mempool_unref_id(struct pw_mempool *pool, uint32_t id) pw_log_debug(NAME" %p: block:%p id:%d fd:%d ref:%d", pool, b, id, b->this.fd, b->this.ref); + b->this.id = SPA_ID_INVALID; + pw_map_remove(&impl->map, id); pw_memblock_unref(&b->this); + return 0; } @@ -661,7 +663,8 @@ void pw_memblock_free(struct pw_memblock *block) if (block->map) block->ref++; - pw_map_remove(&impl->map, block->id); + if (block->id != SPA_ID_INVALID) + pw_map_remove(&impl->map, block->id); spa_list_remove(&b->link); pw_mempool_emit_removed(impl, block); diff --git a/src/pipewire/mem.h b/src/pipewire/mem.h index 433b2c7b..06d92b3a 100644 --- a/src/pipewire/mem.h +++ b/src/pipewire/mem.h @@ -134,8 +134,8 @@ static inline void pw_memblock_unref(struct pw_memblock *mem) pw_memblock_free(mem); } -/** Unref a memblock for given \a id */ -int pw_mempool_unref_id(struct pw_mempool *pool, uint32_t id); +/** Remove a memblock for given \a id */ +int pw_mempool_remove_id(struct pw_mempool *pool, uint32_t id); /** Find memblock for given \a ptr */ struct pw_memblock * pw_mempool_find_ptr(struct pw_mempool *pool, const void *ptr); |