2 * Copyright (C) 2010-2013 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2013-2019 Robin Gareus <robin@gareus.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "libpbd-config.h"
28 #elif defined(__APPLE__) || defined(__FreeBSD__)
30 #include <sys/types.h>
31 #include <sys/sysctl.h>
32 #elif defined(PLATFORM_WINDOWS)
38 #if defined(COMPILER_MSVC) && !defined(PTW32_VERSION)
39 #include <ardourext/pthread.h> // Gets us 'PTW32_VERSION'
43 hardware_concurrency()
45 if (getenv("ARDOUR_CONCURRENCY")) {
46 int c = atoi (getenv("ARDOUR_CONCURRENCY"));
51 #if defined(PTW32_VERSION) || defined(__hpux)
52 return pthread_num_processors_np();
53 #elif defined(__APPLE__)
55 size_t size=sizeof(count);
57 return sysctlbyname("hw.logicalcpu",&count,&size,NULL,0)?0:count;
59 return sysctlbyname("hw.physicalcpu",&count,&size,NULL,0)?0:count;
61 #elif defined(__FreeBSD__)
63 size_t size=sizeof(count);
64 return sysctlbyname("hw.ncpu",&count,&size,NULL,0)?0:count;
65 #elif defined(HAVE_UNISTD) && defined(_SC_NPROCESSORS_ONLN)
66 int const count=sysconf(_SC_NPROCESSORS_ONLN);
67 return (count>0)?count:0;
68 #elif defined(PLATFORM_WINDOWS)
70 GetSystemInfo( &sys_info );
71 return sys_info.dwNumberOfProcessors;