Enhance Windows 7 compatibility.
This commit is contained in:
parent
b19edd54d5
commit
ac27ac75ac
1 changed files with 22 additions and 7 deletions
29
llama-util.h
29
llama-util.h
|
@ -273,13 +273,28 @@ struct llama_mmap {
|
||||||
|
|
||||||
#if _WIN32_WINNT >= _WIN32_WINNT_WIN8
|
#if _WIN32_WINNT >= _WIN32_WINNT_WIN8
|
||||||
if (prefetch) {
|
if (prefetch) {
|
||||||
// Advise the kernel to preload the mapped memory
|
// The PrefetchVirtualMemory API is only present on Windows 8 and above, so we
|
||||||
WIN32_MEMORY_RANGE_ENTRY range;
|
// will dynamically load it using GetProcAddress.
|
||||||
range.VirtualAddress = addr;
|
BOOL (WINAPI *pPrefetchVirtualMemory) (HANDLE, ULONG_PTR, PWIN32_MEMORY_RANGE_ENTRY, ULONG);
|
||||||
range.NumberOfBytes = (SIZE_T)size;
|
HMODULE hKernel32;
|
||||||
if (!PrefetchVirtualMemory(GetCurrentProcess(), 1, &range, 0)) {
|
|
||||||
fprintf(stderr, "warning: PrefetchVirtualMemory failed: %s\n",
|
// This call is guaranteed to succeed.
|
||||||
llama_format_win_err(GetLastError()).c_str());
|
hKernel32 = GetModuleHandleW(L"kernel32.dll");
|
||||||
|
|
||||||
|
// This call may fail if on a pre-Win8 system.
|
||||||
|
pPrefetchVirtualMemory =
|
||||||
|
(BOOL (WINAPI *) (HANDLE, ULONG_PTR, PWIN32_MEMORY_RANGE_ENTRY, ULONG))
|
||||||
|
GetProcAddress(hKernel32, "PrefetchVirtualMemory");
|
||||||
|
|
||||||
|
if (pPrefetchVirtualMemory) {
|
||||||
|
// Advise the kernel to preload the mapped memory.
|
||||||
|
WIN32_MEMORY_RANGE_ENTRY range;
|
||||||
|
range.VirtualAddress = addr;
|
||||||
|
range.NumberOfBytes = (SIZE_T)size;
|
||||||
|
if (!pPrefetchVirtualMemory(GetCurrentProcess(), 1, &range, 0)) {
|
||||||
|
fprintf(stderr, "warning: PrefetchVirtualMemory failed: %s\n",
|
||||||
|
llama_format_win_err(GetLastError()).c_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue