diff options
Diffstat (limited to 'libdimension')
-rw-r--r-- | libdimension/Makefile.am | 6 | ||||
-rw-r--r-- | libdimension/dimension_impl.h | 2 | ||||
-rw-r--r-- | libdimension/platform.c | 35 | ||||
-rw-r--r-- | libdimension/platform.h | 29 | ||||
-rw-r--r-- | libdimension/scene.c | 10 |
5 files changed, 72 insertions, 10 deletions
diff --git a/libdimension/Makefile.am b/libdimension/Makefile.am index 732233e..905606d 100644 --- a/libdimension/Makefile.am +++ b/libdimension/Makefile.am @@ -49,8 +49,6 @@ lib_LTLIBRARIES = libdimension.la libdimension_la_SOURCES = $(nobase_include_HEADERS) \ ambient.c \ - prtree.c \ - prtree.h \ camera.c \ canvas.c \ canvas_pigment.c \ @@ -71,8 +69,12 @@ libdimension_la_SOURCES = $(nobase_include_HEADERS) \ perspective.c \ phong.c \ plane.c \ + platform.c \ + platform.h \ point_light.c \ progress.c \ + prtree.c \ + prtree.h \ raytrace.c \ reflective.c \ scene.c \ diff --git a/libdimension/dimension_impl.h b/libdimension/dimension_impl.h index 3a37386..cf1671e 100644 --- a/libdimension/dimension_impl.h +++ b/libdimension/dimension_impl.h @@ -21,7 +21,9 @@ #ifndef DIMENSION_IMPL_H #define DIMENSION_IMPL_H +#define _GNU_SOURCE #include "dimension.h" +#include "platform.h" #include "threads.h" #include "prtree.h" diff --git a/libdimension/platform.c b/libdimension/platform.c new file mode 100644 index 0000000..6ac15c0 --- /dev/null +++ b/libdimension/platform.c @@ -0,0 +1,35 @@ +/************************************************************************* + * Copyright (C) 2010 Tavian Barnes <tavianator@gmail.com> * + * * + * This file is part of The Dimension Library. * + * * + * The Dimension Library is free software; you can redistribute it and/ * + * or modify it under the terms of the GNU Lesser General Public License * + * as published by the Free Software Foundation; either version 3 of the * + * License, or (at your option) any later version. * + * * + * The Dimension Library is distributed in the hope that it will be * + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty * + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this program. If not, see * + * <http://www.gnu.org/licenses/>. * + *************************************************************************/ + +#include "dimension_impl.h" +#include <unistd.h> /* For sysconf() */ +#include <sched.h> /* For sched_getaffinity() */ + +size_t +dmnsn_ncpus() +{ + cpu_set_t cpuset; + if (sched_getaffinity(0, sizeof(cpuset), &cpuset) == 0) { + return CPU_COUNT(&cpuset); + } else { + dmnsn_error(DMNSN_SEVERITY_MEDIUM, "sched_getaffinity() failed."); + return 1; + } +} diff --git a/libdimension/platform.h b/libdimension/platform.h new file mode 100644 index 0000000..bda83dd --- /dev/null +++ b/libdimension/platform.h @@ -0,0 +1,29 @@ +/************************************************************************* + * Copyright (C) 2010 Tavian Barnes <tavianator@gmail.com> * + * * + * This file is part of The Dimension Library. * + * * + * The Dimension Library is free software; you can redistribute it and/ * + * or modify it under the terms of the GNU Lesser General Public License * + * as published by the Free Software Foundation; either version 3 of the * + * License, or (at your option) any later version. * + * * + * The Dimension Library is distributed in the hope that it will be * + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty * + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this program. If not, see * + * <http://www.gnu.org/licenses/>. * + *************************************************************************/ + +#ifndef DIMENSION_IMPL_UTILITIES_H +#define DIMENSION_IMPL_UTILITIES_H + +#include <stddef.h> + +/* Return the number of CPUs available to dimension */ +size_t dmnsn_ncpus(); + +#endif /* DIMENSION_IMPL_UTILITIES_H */ diff --git a/libdimension/scene.c b/libdimension/scene.c index 10af1b2..c81f936 100644 --- a/libdimension/scene.c +++ b/libdimension/scene.c @@ -18,9 +18,8 @@ * <http://www.gnu.org/licenses/>. * *************************************************************************/ -#include "dimension.h" +#include "dimension_impl.h" #include <stdlib.h> -#include <unistd.h> /* For sysconf */ /* Allocate an empty scene */ dmnsn_scene * @@ -35,12 +34,7 @@ dmnsn_new_scene() scene->lights = dmnsn_new_array(sizeof(dmnsn_light *)); scene->quality = DMNSN_RENDER_FULL; scene->reclimit = 5; - - /* 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; + scene->nthreads = dmnsn_ncpus(); return scene; } |