Browse Source

Use GetLogicalProcessorCount() to count CPUs on Windows.

Bump version to 0.7.
master
samr7 13 years ago
parent
commit
d40577e361
  1. 4
      CHANGELOG
  2. 6
      vanitygen.c
  3. 50
      winglue.c

4
CHANGELOG

@ -28,3 +28,7 @@ Version 0.6, released July 8 2011: @@ -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.

6
vanitygen.c

@ -1969,6 +1969,7 @@ read_file(FILE *fp, char ***result, int *rescount) @@ -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) @@ -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) @@ -1991,6 +1988,7 @@ count_processors(void)
fclose(fp);
return count;
}
#endif
int
start_threads(void *(*func)(void *), void *arg, int nthreads)

50
winglue.c

@ -5,6 +5,56 @@ @@ -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
*/

Loading…
Cancel
Save