1/*
2 Copyright (c) 2006, 2010, Oracle and/or its affiliates
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; version 2 of the License.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16
17/* get the number of (online) CPUs */
18
19#include "mysys_priv.h"
20#ifdef HAVE_UNISTD_H
21#include <unistd.h>
22#endif
23
24static int ncpus=0;
25
26int my_getncpus()
27{
28 if (!ncpus)
29 {
30#ifdef _SC_NPROCESSORS_ONLN
31 ncpus= sysconf(_SC_NPROCESSORS_ONLN);
32#elif defined(__WIN__)
33 SYSTEM_INFO sysinfo;
34
35 /*
36 * We are not calling GetNativeSystemInfo here because (1) we
37 * don't believe that they return different values for number
38 * of processors and (2) if WOW64 limits processors for Win32
39 * then we don't want to try to override that.
40 */
41 GetSystemInfo(&sysinfo);
42
43 ncpus= sysinfo.dwNumberOfProcessors;
44#else
45 /* unknown so play safe: assume SMP and forbid uniprocessor build */
46 ncpus= 2;
47#endif
48 }
49 return ncpus;
50}
51