summaryrefslogtreecommitdiffstats
path: root/libdimension
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-02-23 14:21:48 -0500
committerTavian Barnes <tavianator@gmail.com>2010-02-23 14:22:52 -0500
commitc76c0f017fa884c4b9a04ff7fa3b43d331c82d84 (patch)
tree96927779db344699486933474a48cbb51d61416c /libdimension
parent6260a22ea7a9f08564483ea0beb76b6bdac34bb5 (diff)
downloaddimension-c76c0f017fa884c4b9a04ff7fa3b43d331c82d84.tar.xz
Determine nthreads in dmnsn_new_scene().
Diffstat (limited to 'libdimension')
-rw-r--r--libdimension/raytrace.c15
-rw-r--r--libdimension/scene.c8
2 files changed, 12 insertions, 11 deletions
diff --git a/libdimension/raytrace.c b/libdimension/raytrace.c
index 6721a9b..3fa873c 100644
--- a/libdimension/raytrace.c
+++ b/libdimension/raytrace.c
@@ -19,7 +19,6 @@
*************************************************************************/
#include "dimension_impl.h"
-#include <unistd.h> /* For sysconf */
/*
* Boilerplate for multithreading
@@ -109,20 +108,16 @@ static void *dmnsn_raytrace_scene_multithread_thread(void *ptr);
static int
dmnsn_raytrace_scene_multithread(dmnsn_raytrace_payload *payload)
{
- int i, j, nthreads = payload->scene->nthreads;
+ int i, j;
void *ptr;
int retval = 0;
dmnsn_raytrace_payload *payloads;
pthread_t *threads;
- 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 */
- }
+ unsigned int nthreads = payload->scene->nthreads;
+ /* Sanity check */
+ if (nthreads < 1)
+ nthreads = 1;
payloads = malloc(nthreads*sizeof(dmnsn_raytrace_payload));
if (!payloads) {
diff --git a/libdimension/scene.c b/libdimension/scene.c
index 8973005..8ebf706 100644
--- a/libdimension/scene.c
+++ b/libdimension/scene.c
@@ -20,6 +20,7 @@
#include "dimension.h"
#include <stdlib.h> /* For malloc */
+#include <unistd.h> /* For sysconf */
/* Allocate an empty scene */
dmnsn_scene *
@@ -39,7 +40,12 @@ dmnsn_new_scene()
scene->lights = dmnsn_new_array(sizeof(dmnsn_light *));
scene->quality = DMNSN_RENDER_FULL;
scene->reclimit = 5;
- scene->nthreads = 0;
+
+ /* Find the number of processors/cores running (TODO: do this portably) */
+ int nprocs = sysconf(_SC_NPROCESSORS_ONLN);
+ if (nprocs < 1)
+ nprocs = 1;
+ scene->nthreads = nprocs;
}
return scene;
}