MSVC project changes needed to support the new 'mp3 import' stuff
[ardour.git] / libs / pbd / cpus.cc
1 /*
2  * Copyright (C) 2010-2013 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2013-2019 Robin Gareus <robin@gareus.org>
4  *
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.
9  *
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.
14  *
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.
18  */
19
20 #ifdef WAF_BUILD
21 #include "libpbd-config.h"
22 #endif
23
24 #include <stdlib.h>
25
26 #ifdef __linux__
27 #include <unistd.h>
28 #elif defined(__APPLE__) || defined(__FreeBSD__)
29 #include <stddef.h>
30 #include <sys/types.h>
31 #include <sys/sysctl.h>
32 #elif defined(PLATFORM_WINDOWS)
33 #include <windows.h>
34 #endif
35
36 #include "pbd/cpus.h"
37
38 #if defined(COMPILER_MSVC) && !defined(PTW32_VERSION)
39 #include <ardourext/pthread.h>  // Gets us 'PTW32_VERSION'
40 #endif
41
42 uint32_t
43 hardware_concurrency()
44 {
45         if (getenv("ARDOUR_CONCURRENCY")) {
46                 int c = atoi (getenv("ARDOUR_CONCURRENCY"));
47                 if (c > 0) {
48                         return c;
49                 }
50         }
51 #if defined(PTW32_VERSION) || defined(__hpux)
52         return pthread_num_processors_np();
53 #elif defined(__APPLE__)
54         int count;
55         size_t size=sizeof(count);
56 # ifdef MIXBUS
57         return sysctlbyname("hw.logicalcpu",&count,&size,NULL,0)?0:count;
58 # else
59         return sysctlbyname("hw.physicalcpu",&count,&size,NULL,0)?0:count;
60 # endif
61 #elif defined(__FreeBSD__)
62         int count;
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)
69         SYSTEM_INFO sys_info;
70         GetSystemInfo( &sys_info );
71         return sys_info.dwNumberOfProcessors;
72 #else
73         return 0;
74 #endif
75 }