Clean return value if any win32 call fails.

This commit is contained in:
Tom Lally 2022-09-02 21:09:06 +01:00
parent e3ea4c5046
commit 369ae1d28a

View file

@ -10,8 +10,14 @@ uint64 QueryRamUsage()
{
PROCESS_MEMORY_COUNTERS pmc{};
pmc.cb = sizeof(pmc);
GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
if (GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc)))
{
return pmc.WorkingSetSize;
}
else
{
return 0;
}
}
void QueryProcTime(uint64 &out_now, uint64 &out_user, uint64 &out_kernel)
@ -22,7 +28,8 @@ void QueryProcTime(uint64 &out_now, uint64 &out_user, uint64 &out_kernel)
now.LowPart = ftime.dwLowDateTime;
now.HighPart = ftime.dwHighDateTime;
GetProcessTimes(GetCurrentProcess(), &ftime, &ftime, &fkernel, &fuser);
if (GetProcessTimes(GetCurrentProcess(), &ftime, &ftime, &fkernel, &fuser))
{
kernel.LowPart = fkernel.dwLowDateTime;
kernel.HighPart = fkernel.dwHighDateTime;
@ -32,6 +39,13 @@ void QueryProcTime(uint64 &out_now, uint64 &out_user, uint64 &out_kernel)
out_now = now.QuadPart;
out_user = user.QuadPart;
out_kernel = kernel.QuadPart;
}
else
{
out_now = 0;
out_user = 0;
out_kernel = 0;
}
}
void QueryCoreTimes(uint32 count, ProcessorTime out[])