aboutsummaryrefslogtreecommitdiff
path: root/shm.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-11-02 00:27:05 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-11-02 00:27:05 +0000
commitc6c75298f339f313abb282f27dd3ca02fd7ea26a (patch)
tree92d65872ad3fc1fb4b3fb830e5e5bfe9f8222acd /shm.c
parenttimerfd: use non-blocking mode, fixes dead lock (diff)
shm: automatic buffer purging is now delayed one cycle
This ensures we don't purge a buffer that a user is holding a reference to.
Diffstat (limited to 'shm.c')
-rw-r--r--shm.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/shm.c b/shm.c
index f58ca3e4..9b1af9a4 100644
--- a/shm.c
+++ b/shm.c
@@ -53,10 +53,28 @@ shm_get_buffer(struct wl_shm *shm, int width, int height, unsigned long cookie)
if (!it->item.busy) {
LOG_DBG("cookie=%lx: re-using buffer from cache", cookie);
it->item.busy = true;
+ it->item.purge = false;
return &it->item;
}
}
+ /* Purge buffers marked for purging */
+ tll_foreach(buffers, it) {
+ if (it->item.cookie != cookie)
+ continue;
+
+ if (!it->item.purge)
+ continue;
+
+ assert(!it->item.busy);
+
+ LOG_DBG("cookie=%lx: purging buffer %p (width=%d, height=%d)",
+ cookie, &it->item, it->item.width, it->item.height);
+
+ buffer_destroy(&it->item);
+ tll_remove(buffers, it);
+ }
+
/* Purge old buffers associated with this cookie */
tll_foreach(buffers, it) {
if (it->item.cookie != cookie)
@@ -68,11 +86,8 @@ shm_get_buffer(struct wl_shm *shm, int width, int height, unsigned long cookie)
if (it->item.width == width && it->item.height == height)
continue;
- LOG_DBG("cookie=%lx: purging buffer (width=%d, height=%d)",
- cookie, it->item.width, it->item.height);
-
- buffer_destroy(&it->item);
- tll_remove(buffers, it);
+ LOG_DBG("cookie=%lx: marking buffer %p for purging", cookie, &it->item);
+ it->item.purge = true;
}
/*