diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2023-06-12 17:21:37 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2023-06-12 17:21:37 -0700 |
commit | ddf0fb30de036ee7c714e813442b7ae0809d26f4 (patch) | |
tree | 95ac47dc91b569df5d745ec55e66865f57ea70d3 | |
parent | 300b6beaf106c8fb89eb5da31ca327e7d68ec8b0 (diff) |
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.
-rw-r--r-- | src/til.c | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -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; } |