summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-01-14 13:05:50 -0500
committerTavian Barnes <tavianator@gmail.com>2010-01-14 13:05:50 -0500
commita8b7936b17a2270e6b19cb02f25dedc33a1a076e (patch)
tree2913a0aa2bc8068cb500a456d1ae616240698508
parent2cbebd8502fa8ca6ca65d83c55e478a3ea502627 (diff)
downloaddimension-a8b7936b17a2270e6b19cb02f25dedc33a1a076e.tar.xz
Make number of raytracing worker threads configurable.
-rw-r--r--libdimension/dimension/scene.h3
-rw-r--r--libdimension/raytrace.c14
-rw-r--r--libdimension/scene.c13
3 files changed, 18 insertions, 12 deletions
diff --git a/libdimension/dimension/scene.h b/libdimension/dimension/scene.h
index 2064792..ffc8517 100644
--- a/libdimension/dimension/scene.h
+++ b/libdimension/dimension/scene.h
@@ -57,6 +57,9 @@ typedef struct {
/* Recursion limit */
unsigned int limit;
+
+ /* Number of paralell threads */
+ unsigned int nthreads;
} dmnsn_scene;
/* Create a scene */
diff --git a/libdimension/raytrace.c b/libdimension/raytrace.c
index 0e197a9..31ce24e 100644
--- a/libdimension/raytrace.c
+++ b/libdimension/raytrace.c
@@ -109,18 +109,20 @@ static void *dmnsn_raytrace_scene_multithread_thread(void *ptr);
static int
dmnsn_raytrace_scene_multithread(dmnsn_raytrace_payload *payload)
{
- int i, j, nthreads;
+ int i, j, nthreads = payload->scene->nthreads;
void *ptr;
int retval = 0;
dmnsn_raytrace_payload *payloads;
pthread_t *threads;
- /* Find the number of processors/cores running (TODO: do this portably) */
- nthreads = sysconf(_SC_NPROCESSORS_ONLN);
- if (nthreads < 1) {
- nthreads = 1;
+ if (!nthreads) {
+ /* Find the number of processors/cores running (TODO: do this portably) */
+ nthreads = sysconf(_SC_NPROCESSORS_ONLN);
+ if (nthreads < 1) {
+ nthreads = 1;
+ }
+ /* End non-portable section */
}
- /* End non-portable section */
payloads = malloc(nthreads*sizeof(dmnsn_raytrace_payload));
if (!payloads) {
diff --git a/libdimension/scene.c b/libdimension/scene.c
index 78e1ffb..aec9b12 100644
--- a/libdimension/scene.c
+++ b/libdimension/scene.c
@@ -33,12 +33,13 @@ dmnsn_new_scene()
return NULL;
}
- scene->camera = NULL;
- scene->canvas = NULL;
- scene->objects = dmnsn_new_array(sizeof(dmnsn_object *));
- scene->lights = dmnsn_new_array(sizeof(dmnsn_light *));
- scene->quality = DMNSN_RENDER_FULL;
- scene->limit = 10;
+ scene->camera = NULL;
+ scene->canvas = NULL;
+ scene->objects = dmnsn_new_array(sizeof(dmnsn_object *));
+ scene->lights = dmnsn_new_array(sizeof(dmnsn_light *));
+ scene->quality = DMNSN_RENDER_FULL;
+ scene->limit = 10;
+ scene->nthreads = 0;
}
return scene;
}