shm: Add shm_buffer ref and shm_pool unref functions

Sometimes the compositor wants to make sure a shm pool doesn't disappear
out from under it.

For example, in Enlightenment, rendering happens in a separate thread
while the main thread can still dispatch events.  If a client is destroyed
during rendering, all its resources are cleaned up and its shm pools are
unmapped.  This causes the rendering thread to segfault.

This patch adds a way for the compositor to increment the refcount of the
shm pool so it can't disappear, and decrement it when it's finished.

The ref/unref are asymmetrical (ref returns the pool) because it's
possible the buffer itself will be gone when you need to unref the pool.

Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Signed-off-by: Derek Foreman <derekf@osg.samsung.com>
This commit is contained in:
Derek Foreman 2015-10-19 20:54:49 -05:00
parent 06fb8bd371
commit eba83cd5e1
2 changed files with 49 additions and 0 deletions

View file

@ -362,6 +362,7 @@ wl_resource_get_destroy_listener(struct wl_resource *resource,
resource = tmp, \
tmp = wl_resource_from_link(wl_resource_get_link(resource)->next))
struct wl_shm_pool;
struct wl_shm_buffer;
void
@ -388,6 +389,12 @@ wl_shm_buffer_get_width(struct wl_shm_buffer *buffer);
int32_t
wl_shm_buffer_get_height(struct wl_shm_buffer *buffer);
struct wl_shm_pool *
wl_shm_buffer_ref_pool(struct wl_shm_buffer *buffer);
void
wl_shm_pool_unref(struct wl_shm_pool *pool);
int
wl_display_init_shm(struct wl_display *display);