diff options
author | Tavian Barnes <tavianator@gmail.com> | 2010-06-28 15:57:54 -0600 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2010-06-28 16:01:12 -0600 |
commit | eb4691098767935c1ffd10f7da46796c11eefcfa (patch) | |
tree | cb52c739182961869efc5b41bce68a97f9731807 /libdimension/platform.c | |
parent | 1b77e953067ce43515e96f99ecafa2ea468a60bc (diff) | |
download | dimension-eb4691098767935c1ffd10f7da46796c11eefcfa.tar.xz |
Use sched_getaffinity() rather than sysconf(_SC_NPROCESSORS_ONLN).
Also, abstract cpu counting into dedicated dmnsn_ncpus() function.
Diffstat (limited to 'libdimension/platform.c')
-rw-r--r-- | libdimension/platform.c | 35 |
1 files changed, 35 insertions, 0 deletions
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; + } +} |