diff --git a/CHANGELOG b/CHANGELOG index 4a80948..b364639 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -28,3 +28,7 @@ Version 0.6, released July 8 2011: - Fix calculation of difficulty for multiple prefixes - When prefixes overlap, output the discarded prefix as well as the existing prefix with which it overlaps + +Version 0.7, released July 8 2011: + - Use GetLogicalProcessorInformation() to count CPUs on Windows, + because GetActiveProcessorCount() is Windows 7 and newer. diff --git a/vanitygen.c b/vanitygen.c index 2c805cc..b55e335 100644 --- a/vanitygen.c +++ b/vanitygen.c @@ -1969,6 +1969,7 @@ read_file(FILE *fp, char ***result, int *rescount) return ret; } +#if !defined(_WIN32) int count_processors(void) { @@ -1976,10 +1977,6 @@ count_processors(void) char buf[512]; int count = 0; -#if defined(_WIN32) - return GetActiveProcessorCount(ALL_PROCESSOR_GROUPS); -#endif - fp = fopen("/proc/cpuinfo", "r"); if (!fp) return -1; @@ -1991,6 +1988,7 @@ count_processors(void) fclose(fp); return count; } +#endif int start_threads(void *(*func)(void *), void *arg, int nthreads) diff --git a/winglue.c b/winglue.c index 0239bdf..c125914 100644 --- a/winglue.c +++ b/winglue.c @@ -5,6 +5,56 @@ #define INLINE #define snprintf _snprintf + +int +count_processors(void) +{ + typedef BOOL (WINAPI *LPFN_GLPI)( + PSYSTEM_LOGICAL_PROCESSOR_INFORMATION, PDWORD); + LPFN_GLPI glpi; + PSYSTEM_LOGICAL_PROCESSOR_INFORMATION buffer = NULL, ptr; + DWORD size = 0, count = 0, pos = 0, i, ret; + + glpi = (LPFN_GLPI) GetProcAddress(GetModuleHandle(TEXT("kernel32")), + "GetLogicalProcessorInformation"); + if (!glpi) + return -1; + + while (1) { + ret = glpi(buffer, &size); + if (ret) + break; + if (buffer) + free(buffer); + if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) + return -1; + buffer = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION) malloc(size); + if (!buffer) + return -1; + } + + for (ptr = buffer; + (pos + sizeof(*ptr)) <= size; + ptr++, pos += sizeof(*ptr)) { + switch (ptr->Relationship) { + case RelationProcessorCore: + for (i = ptr->ProcessorMask; i != 0; i >>= 1) { + if (i & 1) + count++; + } + count++; + break; + default: + break; + } + } + + if (buffer) + free(buffer); + return count; +} + + /* * struct timeval compatibility for Win32 */