faridz@apache.org wrote:
> Author: faridz
> Date: Wed Jun 27 06:17:27 2007
> New Revision: 551156
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=551156
> Log:
> 2007-06-27 Farid Zaripov <Farid_Zaripov@epam.com>
>
> * thread.cpp (rw_get_cpus) [_WIN32]: Added Windows version of the function.
Cool, thanks! Eventually, I'd like to do it this way (i.e.,
programmatically as opposed to using the shell) on all
platforms.
Martin
>
> Modified:
> incubator/stdcxx/trunk/tests/src/thread.cpp
>
> Modified: incubator/stdcxx/trunk/tests/src/thread.cpp
> URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/src/thread.cpp?view=diff&rev=551156&r1=551155&r2=551156
> ==============================================================================
> --- incubator/stdcxx/trunk/tests/src/thread.cpp (original)
> +++ incubator/stdcxx/trunk/tests/src/thread.cpp Wed Jun 27 06:17:27 2007
> @@ -31,11 +31,12 @@
>
> #include <rw_thread.h>
> #include <stddef.h> // for size_t
> -#include <stdio.h> // for FILE, fscanf(), popen()
> #include <string.h> // for memset()
>
> -#ifdef _WIN32
> -# define popen(name, mode) _popen(name, mode)
> +#ifndef _WIN32
> +# include <stdio.h> // for FILE, fscanf(), popen()
> +#else // _WIN32
> +# include <windows.h> // for GetSystemInfo()
> #endif // _WIN32
>
> /**************************************************************************/
> @@ -380,45 +381,44 @@
> _TEST_EXPORT int
> rw_get_cpus ()
> {
> +#ifndef _WIN32
> +
> const char* const cmd = {
> // shell command(s) to obtain the number of processors
>
> -#ifdef _RWSTD_OS_AIX
> +# ifdef _RWSTD_OS_AIX
> // AIX: /etc/lsdev -Cc processor | wc -l
> "/etc/lsdev -Cc processor | /usr/bin/wc -l"
> -#elif defined (_RWSTD_OS_LINUX)
> +# elif defined (_RWSTD_OS_LINUX)
> // Linux: cat /proc/cpuinfo | grep processor | wc -l
> "/usr/bin/cat /proc/cpuinfo "
> " | /usr/bin/grep processor "
> " | /usr/bin/wc -l"
> -#elif defined (_RWSTD_OS_FREEBSD)
> +# elif defined (_RWSTD_OS_FREEBSD)
> // FreeBSD: /sbin/sysctl -n hw.ncpu
> "/sbin/sysctl -n hw.ncpu"
> -#elif defined (_RWSTD_OS_HP_UX)
> +# elif defined (_RWSTD_OS_HP_UX)
> // HP-UX: /etc/ioscan -k -C processor | grep processor | wc -l
> "/etc/ioscan -k -C processor "
> " | /usr/bin/grep processor "
> " | /usr/bin/wc -l"
> -#elif defined (_RWSTD_OS_IRIX64)
> +# elif defined (_RWSTD_OS_IRIX64)
> // IRIX: hinv | /usr/bin/grep "^[1-9][0-9]* .* Processor"
> "/sbin/hinv "
> " | /usr/bin/grep \"^[1-9][0-9]* .* Processor\""
> -#elif defined (_RWSTD_OS_OSF1)
> +# elif defined (_RWSTD_OS_OSF1)
> // Tru64 UNIX: /usr/sbin/psrinfo | grep online | wc -l
> "/usr/sbin/psrinfo "
> " | /usr/bin/grep on[-]*line "
> " | /usr/bin wc -l"
> -#elif defined (_RWSTD_OS_SUNOS)
> +# elif defined (_RWSTD_OS_SUNOS)
> // Solaris: /usr/bin/mpstat | wc -l
> "/usr/bin/mpstat "
> " | /usr/bin/grep -v \"^CPU\" "
> " | /usr/bin/wc -l"
> -#elif defined (_RWSTD_OS_WINDOWS)
> - // Windows: ???
> - 0
> -#else
> +# else
> 0
> -#endif
> +# endif
>
> };
>
> @@ -441,6 +441,14 @@
> }
>
> return ncpus;
> +
> +#else // _WIN32
> +
> + SYSTEM_INFO info;
> + GetSystemInfo (&info);
> + return int (info.dwNumberOfProcessors);
> +
> +#endif // _WIN32
> }
>
> /**************************************************************************/
>
>
>
|