From ddf0fb30de036ee7c714e813442b7ae0809d26f4 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Mon, 12 Jun 2023 17:21:37 -0700 Subject: til: register contexts on-stream @ create time Module contexts are now discoverable via the stream a la til_stream_find_module_contexts(). The current architecture has the stream adding a reference to all the contexts registered. So even if they get unreferenced by their creators, they will linger on-stream. There's a gc mechanism til_stream_gc_module_contexts() which can be used to trigger a cleanup of contexts _only_ referenced by the stream. It's unclear as of yet if this is the way to go long-term, but it lets things work for now and allows some iterating and experimentation to see where to go next. --- src/til.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/til.c') diff --git a/src/til.c b/src/til.c index 5a9a964..e4df34e 100644 --- a/src/til.c +++ b/src/til.c @@ -402,6 +402,9 @@ void til_module_render(til_module_context_t *context, til_stream_t *stream, unsi * to explicitly set n_cpus, just pass the value. This is primarily intended for * the purpose of explicitly constraining rendering parallelization to less than n_threads, * if n_cpus is specified > n_threads it won't increase n_threads... + * + * if stream is non-NULL, the created contexts will be registered on-stream w/handle @setup->path. + * any existing contexts @setup->path, will be replaced by the new one. */ int til_module_create_contexts(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup, size_t n_contexts, til_module_context_t **res_contexts) { @@ -432,6 +435,18 @@ int til_module_create_contexts(const til_module_t *module, til_stream_t *stream, res_contexts[i] = context; } + if (stream) { + int r; + + r = til_stream_register_module_contexts(stream, n_contexts, res_contexts); + if (r < 0) { + for (size_t i = 0; i < n_contexts; i++) + res_contexts[i] = til_module_context_free(res_contexts[i]); + + return r; + } + } + return 0; } -- cgit v1.2.1