diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2014-09-16 18:24:29 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2014-09-16 18:24:29 +0200 |
commit | 0e6fe4f1cabbcfc85e790552ae02ab78a7c1be2d (patch) | |
tree | cbbcc48b10d5edcf7ade1a516cab5fe0f74272fe /src/system.c | |
parent | 44353ca8aeaff369669f5108a6cadda895842673 (diff) | |
download | biruda-0e6fe4f1cabbcfc85e790552ae02ab78a7c1be2d.tar.gz biruda-0e6fe4f1cabbcfc85e790552ae02ab78a7c1be2d.tar.bz2 |
added detection of cpus
Diffstat (limited to 'src/system.c')
-rw-r--r-- | src/system.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/system.c b/src/system.c new file mode 100644 index 0000000..203e2e9 --- /dev/null +++ b/src/system.c @@ -0,0 +1,24 @@ +#include "system.h" + +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN +#include <windows.h> +#else +#include <unistd.h> +#endif + +unsigned int available_cpus( void ) +{ +#ifdef _WIN32 +#else + long nprocs = sysconf( _SC_NPROCESSORS_ONLN ); + if( nprocs < -1 ) { + // assuming one CPU if we can't detect the number of + // CPUs (safe fallback) + return 1; + } +#endif + + return nprocs; +} + |