diff options
author | Lasse Collin <lasse.collin@tukaani.org> | 2009-09-19 09:47:30 +0300 |
---|---|---|
committer | Lasse Collin <lasse.collin@tukaani.org> | 2009-09-19 09:47:30 +0300 |
commit | e599bba4216c0edb8cc8f40adad3a6dba88685f4 (patch) | |
tree | d52c699f599e276ff65302e5854a26998da1a928 /src/common/cpucores.h | |
parent | Fix incorrect use of "restrict". (diff) | |
download | xz-e599bba4216c0edb8cc8f40adad3a6dba88685f4.tar.xz |
Various changes.
Separate a few reusable components from XZ Utils specific
code. The reusable code is now in "tuklib" modules. A few
more could be separated still, e.g. bswap.h.
Fix some bugs in lzmainfo.
Fix physmem and cpucores code on OS/2. Thanks to Elbert Pol
for help.
Add OpenVMS support into physmem. Add a few #ifdefs to ease
building XZ Utils on OpenVMS. Thanks to Jouk Jansen for the
original patch.
Diffstat (limited to '')
-rw-r--r-- | src/common/tuklib_cpucores.c (renamed from src/common/cpucores.h) | 39 |
1 files changed, 17 insertions, 22 deletions
diff --git a/src/common/cpucores.h b/src/common/tuklib_cpucores.c index 370c3cec..0a8081ff 100644 --- a/src/common/cpucores.h +++ b/src/common/tuklib_cpucores.c @@ -1,7 +1,7 @@ /////////////////////////////////////////////////////////////////////////////// // -/// \file cpucores.h -/// \brief Get the number of online CPU cores +/// \file tuklib_cpucores.c +/// \brief Get the number of CPU cores online // // Author: Lasse Collin // @@ -10,42 +10,37 @@ // /////////////////////////////////////////////////////////////////////////////// -#ifndef CPUCORES_H -#define CPUCORES_H +#include "tuklib_cpucores.h" -#if defined(HAVE_CPUCORES_SYSCONF) -# include <unistd.h> - -#elif defined(HAVE_CPUCORES_SYSCTL) +#if defined(TUKLIB_CPUCORES_SYSCTL) # ifdef HAVE_SYS_PARAM_H # include <sys/param.h> # endif -# ifdef HAVE_SYS_SYSCTL_H -# include <sys/sysctl.h> -# endif +# include <sys/sysctl.h> + +#elif defined(TUKLIB_CPUCORES_SYSCONF) +# include <unistd.h> #endif -static inline uint32_t -cpucores(void) +extern uint32_t +tuklib_cpucores(void) { uint32_t ret = 0; -#if defined(HAVE_CPUCORES_SYSCONF) - const long cpus = sysconf(_SC_NPROCESSORS_ONLN); - if (cpus > 0) - ret = (uint32_t)(cpus); - -#elif defined(HAVE_CPUCORES_SYSCTL) +#if defined(TUKLIB_CPUCORES_SYSCTL) int name[2] = { CTL_HW, HW_NCPU }; int cpus; size_t cpus_size = sizeof(cpus); if (sysctl(name, 2, &cpus, &cpus_size, NULL, 0) != -1 && cpus_size == sizeof(cpus) && cpus > 0) - ret = (uint32_t)(cpus); + ret = (uint32_t)cpus; + +#elif defined(TUKLIB_CPUCORES_SYSCONF) + const long cpus = sysconf(_SC_NPROCESSORS_ONLN); + if (cpus > 0) + ret = (uint32_t)cpus; #endif return ret; } - -#endif |