shm: replace 'locked' attribute with a ref-counter

The initial ref-count is either 1 or 0, depending on whether the
buffer is supposed to be released "immeidately" (meaning, as soon as
the compositor releases it).

Two new user facing functions have been added: shm_addref() and
shm_unref().

Our renderer now uses these two functions instead of manually setting
and clearing the 'locked' attribute.

shm_unref() will decrement the ref-counter, and destroy the buffer
when the counter reaches zero. Except if the buffer is currently
"busy" (compositor owned), in which case destruction is deferred to
the release event. The buffer is still removed from the list though.
This commit is contained in:
Daniel Eklöf 2021-07-16 16:47:57 +02:00
parent 69260dd960
commit 232fb20269
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
4 changed files with 60 additions and 53 deletions

View file

@ -2324,19 +2324,18 @@ 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;
shm_unref(term->render.last_buf);
term->render.last_buf = NULL;
}
term->render.last_buf = buf;
term->render.was_flashing = term->flash.active;
term->render.was_searching = term->is_searching;
buf->locked = true;
shm_addref(buf);
buf->age = 0;
xassert(buf->scroll_damage == NULL);
free(term->render.last_buf->scroll_damage);
buf->scroll_damage_count = tll_length(term->grid->scroll_damage);
buf->scroll_damage = xmalloc(
buf->scroll_damage_count * sizeof(buf->scroll_damage[0]));
@ -3484,8 +3483,7 @@ 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;
shm_unref(term->render.last_buf);
term->render.last_buf = NULL;
term_damage_view(term);
render_refresh_csd(term);