From 2a758d61d9ee5c8ae43bf5a6d974d27cc6779ef2 Mon Sep 17 00:00:00 2001 From: "deanm@chromium.org" Date: Wed, 17 Sep 2008 10:09:39 +0000 Subject: Add a class for extracting system-specific information, like the number of processors. Review URL: http://codereview.chromium.org/3084 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2302 0039d316-1c4b-4281-b951-d872f2087c98 --- base/sys_info_posix.cc | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 base/sys_info_posix.cc (limited to 'base/sys_info_posix.cc') diff --git a/base/sys_info_posix.cc b/base/sys_info_posix.cc new file mode 100644 index 0000000..093e607 --- /dev/null +++ b/base/sys_info_posix.cc @@ -0,0 +1,28 @@ +// Copyright (c) 2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/sys_info.h" + +#include +#include +#include + +#include "base/basictypes.h" +#include "base/logging.h" + +namespace base { + +int SysInfo::NumberOfProcessors() { + // It seems that sysconf returns the number of "logical" processors on both + // mac and linux. So we get the number of "online logical" processors. + long res = sysconf(_SC_NPROCESSORS_ONLN); + if (res == -1) { + NOTREACHED(); + return 1; + } + + return static_cast(res); +} + +} // namespace base -- cgit v1.1