mirror of
https://github.com/GOSTSec/vanitygen
synced 2025-02-07 12:24:20 +00:00
Use GetLogicalProcessorCount() to count CPUs on Windows.
Bump version to 0.7.
This commit is contained in:
parent
03f4e05ebf
commit
d40577e361
@ -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.
|
||||
|
@ -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)
|
||||
|
50
winglue.c
50
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
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user