win: return fractional seconds in uv_uptime() (#3455)

Some systems return fractional seconds, some return full seconds.
On Windows uptime was artificially rounded down.

Fixes #3447.
This commit is contained in:
Luca Adrian L 2022-02-08 14:23:39 +01:00 committed by GitHub
parent de24da8c11
commit 50c1d00839
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -312,7 +312,7 @@ API
.. c:function:: int uv_uptime(double* uptime)
Gets the current system uptime.
Gets the current system uptime. Depending on the system full or fractional seconds are returned.
.. c:function:: int uv_getrusage(uv_rusage_t* rusage)

View File

@ -608,8 +608,8 @@ int uv_uptime(double* uptime) {
BYTE* address = (BYTE*) object_type + object_type->DefinitionLength +
counter_definition->CounterOffset;
uint64_t value = *((uint64_t*) address);
*uptime = floor((double) (object_type->PerfTime.QuadPart - value) /
(double) object_type->PerfFreq.QuadPart);
*uptime = (double) (object_type->PerfTime.QuadPart - value) /
(double) object_type->PerfFreq.QuadPart;
uv__free(malloced_buffer);
return 0;
}