shm: add shm_get_many() - allows buffers to share a single pool

shm_get_many() always returns new buffers (i.e. never old, cached
ones). The newly allocated buffers are also marked for immediate
purging, meaning they’ll be destroyed on the next call to either
shm_get_buffer(), or shm_get_many().

Furthermore, we add a new attribute, ‘locked’, to the buffer
struct. When auto purging buffers, look at this instead of comparing
cookies.

Buffer consumers are expected to set ‘locked’ while they hold a
reference to it, and don’t want it destroyed behind their back.
This commit is contained in:
Daniel Eklöf 2021-07-15 18:32:19 +02:00
parent 5e64c67c25
commit 7533684d8f
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
3 changed files with 274 additions and 129 deletions

View file

@ -2322,6 +2322,7 @@ grid_render(struct terminal *term)
}
if (term->render.last_buf != NULL) {
term->render.last_buf->locked = false;
free(term->render.last_buf->scroll_damage);
term->render.last_buf->scroll_damage = NULL;
}
@ -2330,6 +2331,7 @@ grid_render(struct terminal *term)
term->render.was_flashing = term->flash.active;
term->render.was_searching = term->is_searching;
buf->locked = true;
buf->age = 0;
xassert(buf->scroll_damage == NULL);
@ -3416,6 +3418,8 @@ damage_view:
tll_free(term->normal.scroll_damage);
tll_free(term->alt.scroll_damage);
if (term->render.last_buf != NULL)
term->render.last_buf->locked = false;
term->render.last_buf = NULL;
term_damage_view(term);
render_refresh_csd(term);