From eb4691098767935c1ffd10f7da46796c11eefcfa Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Mon, 28 Jun 2010 15:57:54 -0600 Subject: Use sched_getaffinity() rather than sysconf(_SC_NPROCESSORS_ONLN). Also, abstract cpu counting into dedicated dmnsn_ncpus() function. --- libdimension/platform.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 libdimension/platform.c (limited to 'libdimension/platform.c') 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 * + * * + * 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 * + * . * + *************************************************************************/ + +#include "dimension_impl.h" +#include /* For sysconf() */ +#include /* 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; + } +} -- cgit v1.2.3