diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2019-11-23 16:08:07 -0800 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2019-11-23 16:14:34 -0800 |
commit | ade362b53d721bc2e2c7a62a30c4345014e5f5ce (patch) | |
tree | 028914a89365c43047ecb9af1368d8c3304f7e5c | |
parent | 796b3a8b0669ee5e09c6faba6614e3f228d36595 (diff) |
rototiller: pass num_cpus to .create_context()
Back in the day, there was no {create,destroy}_context(), so passing
num_cpus to just prepare_frame made sense. Modules then would
implicitly initialize themselves on the first prepare_frame() call
using a static initialized variable.
Since then things have been decomposed a bit for more sophisticated
(and cleaner) modules. It can be necessary to allocate per-cpu data
structures and the natural place to do that is @ create_context(). So
this commit wires that up.
A later commit will probably have to plumb a "current cpu" identifier
into the render_fragment() function. Because a per-cpu data structure
isn't particularly useful if you can't easily address it from within
your execution context.
-rw-r--r-- | src/modules/flui2d/flui2d.c | 2 | ||||
-rw-r--r-- | src/modules/julia/julia.c | 2 | ||||
-rw-r--r-- | src/modules/plasma/plasma.c | 2 | ||||
-rw-r--r-- | src/modules/ray/ray.c | 2 | ||||
-rw-r--r-- | src/modules/roto/roto.c | 2 | ||||
-rw-r--r-- | src/modules/rtv/rtv.c | 8 | ||||
-rw-r--r-- | src/modules/sparkler/sparkler.c | 2 | ||||
-rw-r--r-- | src/modules/submit/submit.c | 2 | ||||
-rw-r--r-- | src/modules/swab/swab.c | 2 | ||||
-rw-r--r-- | src/rototiller.c | 8 | ||||
-rw-r--r-- | src/rototiller.h | 2 |
11 files changed, 18 insertions, 16 deletions
diff --git a/src/modules/flui2d/flui2d.c b/src/modules/flui2d/flui2d.c index 65aeace..624202b 100644 --- a/src/modules/flui2d/flui2d.c +++ b/src/modules/flui2d/flui2d.c @@ -187,7 +187,7 @@ typedef struct flui2d_context_t { } flui2d_context_t; -static void * flui2d_create_context(void) +static void * flui2d_create_context(unsigned num_cpus) { flui2d_context_t *ctxt; diff --git a/src/modules/julia/julia.c b/src/modules/julia/julia.c index b35116b..61ed102 100644 --- a/src/modules/julia/julia.c +++ b/src/modules/julia/julia.c @@ -66,7 +66,7 @@ static uint32_t colors[] = { }; -static void * julia_create_context(void) +static void * julia_create_context(unsigned num_cpus) { return calloc(1, sizeof(julia_context_t)); } diff --git a/src/modules/plasma/plasma.c b/src/modules/plasma/plasma.c index 245cf3c..731838f 100644 --- a/src/modules/plasma/plasma.c +++ b/src/modules/plasma/plasma.c @@ -47,7 +47,7 @@ static void init_plasma(int32_t *costab, int32_t *sintab) } -static void * plasma_create_context(void) +static void * plasma_create_context(unsigned num_cpus) { return calloc(1, sizeof(plasma_context_t)); } diff --git a/src/modules/ray/ray.c b/src/modules/ray/ray.c index c0c067e..99e6609 100644 --- a/src/modules/ray/ray.c +++ b/src/modules/ray/ray.c @@ -124,7 +124,7 @@ typedef struct ray_context_t { } ray_context_t; -static void * ray_create_context(void) +static void * ray_create_context(unsigned num_cpus) { return calloc(1, sizeof(ray_context_t)); } diff --git a/src/modules/roto/roto.c b/src/modules/roto/roto.c index c5c951d..050b129 100644 --- a/src/modules/roto/roto.c +++ b/src/modules/roto/roto.c @@ -32,7 +32,7 @@ static int32_t costab[FIXED_TRIG_LUT_SIZE], sintab[FIXED_TRIG_LUT_SIZE]; static uint8_t texture[256][256]; static color_t palette[2]; -static void * roto_create_context(void) +static void * roto_create_context(unsigned num_cpus) { return calloc(1, sizeof(roto_context_t)); } diff --git a/src/modules/rtv/rtv.c b/src/modules/rtv/rtv.c index c4c6dd2..dd9ece8 100644 --- a/src/modules/rtv/rtv.c +++ b/src/modules/rtv/rtv.c @@ -31,6 +31,7 @@ typedef struct rtv_context_t { const rototiller_module_t **modules; size_t n_modules; + unsigned n_cpus; time_t next_switch, next_hide_caption; const rototiller_module_t *module, *last_module; @@ -41,7 +42,7 @@ typedef struct rtv_context_t { } rtv_context_t; static void setup_next_module(rtv_context_t *ctxt); -static void * rtv_create_context(void); +static void * rtv_create_context(unsigned num_cpus); static void rtv_destroy_context(void *context); static void rtv_prepare_frame(void *context, unsigned n_cpus, fb_fragment_t *fragment, rototiller_fragmenter_t *res_fragmenter); static void rtv_finish_frame(void *context, fb_fragment_t *fragment); @@ -152,14 +153,15 @@ static void setup_next_module(rtv_context_t *ctxt) } if (ctxt->module->create_context) - ctxt->module_ctxt = ctxt->module->create_context(); + ctxt->module_ctxt = ctxt->module->create_context(ctxt->n_cpus); } -static void * rtv_create_context(void) +static void * rtv_create_context(unsigned num_cpus) { rtv_context_t *ctxt = calloc(1, sizeof(rtv_context_t)); + ctxt->n_cpus = num_cpus; ctxt->snow_module = rototiller_lookup_module("snow"); rototiller_get_modules(&ctxt->modules, &ctxt->n_modules); setup_next_module(ctxt); diff --git a/src/modules/sparkler/sparkler.c b/src/modules/sparkler/sparkler.c index 7ffa3d6..9462438 100644 --- a/src/modules/sparkler/sparkler.c +++ b/src/modules/sparkler/sparkler.c @@ -24,7 +24,7 @@ typedef struct sparkler_context_t { extern particle_ops_t simple_ops; -static void * sparkler_create_context(void) +static void * sparkler_create_context(unsigned num_cpus) { static int initialized; sparkler_context_t *ctxt; diff --git a/src/modules/submit/submit.c b/src/modules/submit/submit.c index 3fc2ddd..340783c 100644 --- a/src/modules/submit/submit.c +++ b/src/modules/submit/submit.c @@ -261,7 +261,7 @@ static void setup_grid(submit_context_t *ctxt) } -static void * submit_create_context(void) +static void * submit_create_context(unsigned num_cpus) { submit_context_t *ctxt; diff --git a/src/modules/swab/swab.c b/src/modules/swab/swab.c index 6528900..aa53566 100644 --- a/src/modules/swab/swab.c +++ b/src/modules/swab/swab.c @@ -60,7 +60,7 @@ static inline uint32_t color_to_uint32(color_t color) { } -static void * swab_create_context(void) +static void * swab_create_context(unsigned num_cpus) { swab_context_t *ctxt; diff --git a/src/rototiller.c b/src/rototiller.c index 74ba006..a5d0927 100644 --- a/src/rototiller.c +++ b/src/rototiller.c @@ -416,13 +416,13 @@ int main(int argc, const char *argv[]) exit_if(!fps_setup(), "unable to setup fps counter"); - exit_if(rototiller.module->create_context && - !(rototiller.module_context = rototiller.module->create_context()), - "unable to create module context"); - pexit_if(!(rototiller.threads = threads_create()), "unable to create rendering threads"); + exit_if(rototiller.module->create_context && + !(rototiller.module_context = rototiller.module->create_context(threads_num_threads(rototiller.threads))), + "unable to create module context"); + pexit_if(pthread_create(&rototiller.thread, NULL, rototiller_thread, &rototiller) != 0, "unable to create dispatch thread"); diff --git a/src/rototiller.h b/src/rototiller.h index ca2559a..e60eece 100644 --- a/src/rototiller.h +++ b/src/rototiller.h @@ -11,7 +11,7 @@ typedef struct settings_t settings; typedef struct setting_desc_t setting_desc_t; typedef struct rototiller_module_t { - void * (*create_context)(void); + void * (*create_context)(unsigned n_cpus); void (*destroy_context)(void *context); void (*prepare_frame)(void *context, unsigned n_cpus, fb_fragment_t *fragment, rototiller_fragmenter_t *res_fragmenter); void (*render_fragment)(void *context, fb_fragment_t *fragment); |