summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2023-05-29 16:10:56 -0700
committerVito Caputo <vcaputo@pengaru.com>2023-05-30 08:30:55 -0700
commitc94e4683956a09de468174ff37951abf7822d5a3 (patch)
tree1b85607868267c5606025864e5322a71e6e9b572 /src
parentc975ca1063f85d77fb2dae10d8de7c991863c32e (diff)
til: add til_module_setup_finalize() helper
Preparatory commit for til_module_create_context() requiring setups even when there's no til_module_t.setup() method. This helper will produce the minimal til_setup_t in such cases, or hand off the task to til_module_t.setup() when present. Note the need for passing res_setting and res_desc to til_module_t.setup() despite not being a settings-construction scenario. This is because of how modules using nested settings tend to use res_setting for storing the current setting in accessing the nested instance, which must still occur even when just baking the complete setup. It's expected that any composite/meta modules utilizing other modules will use this helper to produce the baked setups, instead of the ad-hoc direct calling of til_module_t.setup() they do presently.
Diffstat (limited to 'src')
-rw-r--r--src/til.c44
-rw-r--r--src/til.h1
2 files changed, 45 insertions, 0 deletions
diff --git a/src/til.c b/src/til.c
index 2fa0978..65d1c8c 100644
--- a/src/til.c
+++ b/src/til.c
@@ -322,6 +322,7 @@ int til_module_setup(const til_settings_t *settings, til_setting_t **res_setting
}
+/* TODO: rename to til_module_setup_randomize() */
/* originally taken from rtv, this randomizes a module's setup @res_setup, args @res_arg
* returns 0 on no setup, 1 on setup successful with results stored @res_*, -errno on error.
*/
@@ -415,6 +416,49 @@ int til_module_randomize_setup(const til_module_t *module, unsigned seed, til_se
}
+/* This turns the incoming module+setings into a "baked" til_setup_t,
+ * if module->setup() isn't provided, a minimal til_setup_t is still produced.
+ */
+int til_module_setup_finalize(const til_module_t *module, const til_settings_t *module_settings, til_setup_t **res_setup)
+{
+ til_setting_t *setting;
+ const til_setting_desc_t *desc;
+ int r;
+
+ assert(module);
+ assert(module_settings);
+ assert(res_setup);
+
+ if (!module->setup) {
+ til_setup_t *setup;
+
+ setup = til_setup_new(module_settings, sizeof(*setup), NULL);
+ if (!setup)
+ return -ENOMEM;
+
+ *res_setup = setup;
+
+ return 0;
+ }
+
+ /* TODO: note passing &setting and &desc when finalizing is really only necessary
+ * because of how nested settings get found via &setting, and modules that do this
+ * currently tend to access (*res_setting)->value_as_nested_settings and that needs
+ * to occur even when just finalizing. A future change may rework how modules do
+ * this, but let's just pass the res_setting and res_desc pointers to keep things
+ * happy for now. Long-term it should really be possible to pass NULL for those,
+ * at least when you're just finalizing.
+ */
+ r = module->setup(module_settings, &setting, &desc, res_setup);
+ if (r < 0)
+ return r;
+ if (r > 0) /* FIXME: this should probably free desc */
+ return -EINVAL; /* module_settings is incomplete, but we're not performing setup here. */
+
+ return r;
+}
+
+
/* generic fragmenter using a horizontal slice per cpu according to context->n_cpus */
int til_fragmenter_slice_per_cpu(til_module_context_t *context, const til_fb_fragment_t *fragment, unsigned number, til_fb_fragment_t *res_fragment)
{
diff --git a/src/til.h b/src/til.h
index fabee0a..e9c6b82 100644
--- a/src/til.h
+++ b/src/til.h
@@ -47,6 +47,7 @@ int til_module_create_context(const til_module_t *module, til_stream_t *stream,
til_module_context_t * til_module_destroy_context(til_module_context_t *context, til_stream_t *stream);
int til_module_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup);
int til_module_randomize_setup(const til_module_t *module, unsigned seed, til_setup_t **res_setup, char **res_arg);
+int til_module_setup_finalize(const til_module_t *module, const til_settings_t *module_settings, til_setup_t **res_setup);
int til_fragmenter_slice_per_cpu(til_module_context_t *context, const til_fb_fragment_t *fragment, unsigned number, til_fb_fragment_t *res_fragment);
int til_fragmenter_tile64(til_module_context_t *context, const til_fb_fragment_t *fragment, unsigned number, til_fb_fragment_t *res_fragment);
© All Rights Reserved