mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-13 04:27:47 -05:00
render worker context: allocate, and let worker threads free
Since we now initialize the worker threads from term_init(), which returns before the threads terminate, we can no longer use stack-allocated worker contexts. We _could_ put them in the terminal struct. But a simpler solution is to allocate them in term_init(), and let the threads free them when they don't need them anymore.
This commit is contained in:
parent
720d0df067
commit
8e6f87eb17
2 changed files with 6 additions and 4 deletions
1
render.c
1
render.c
|
|
@ -374,6 +374,7 @@ render_worker_thread(void *_ctx)
|
|||
struct render_worker_context *ctx = _ctx;
|
||||
struct terminal *term = ctx->term;
|
||||
const int my_id = ctx->my_id;
|
||||
free(ctx);
|
||||
|
||||
char proc_title[16];
|
||||
snprintf(proc_title, sizeof(proc_title), "foot:render:%d", my_id);
|
||||
|
|
|
|||
|
|
@ -219,7 +219,7 @@ term_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl,
|
|||
int delay_upper_fd = -1;
|
||||
|
||||
struct terminal *term = NULL;
|
||||
struct render_worker_context worker_context[conf->render_worker_count];
|
||||
struct render_worker_context *worker_context[conf->render_worker_count];
|
||||
|
||||
if ((ptmx = posix_openpt(O_RDWR | O_NOCTTY)) == -1) {
|
||||
LOG_ERRNO("failed to open PTY");
|
||||
|
|
@ -343,9 +343,10 @@ term_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl,
|
|||
|
||||
term->render.workers.threads = calloc(term->render.workers.count, sizeof(term->render.workers.threads[0]));
|
||||
for (size_t i = 0; i < term->render.workers.count; i++) {
|
||||
worker_context[i].term = term;
|
||||
worker_context[i].my_id = 1 + i;
|
||||
thrd_create(&term->render.workers.threads[i], &render_worker_thread, &worker_context[i]);
|
||||
worker_context[i] = malloc(sizeof(*worker_context[i]));
|
||||
worker_context[i]->term = term;
|
||||
worker_context[i]->my_id = 1 + i;
|
||||
thrd_create(&term->render.workers.threads[i], &render_worker_thread, worker_context[i]);
|
||||
}
|
||||
|
||||
font_list_t font_names = tll_init();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue