mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-04-18 05:42:35 +00:00
Implement ms time with GetSystemTimeAsFile time.
There's a potential race condition with calling time(NULL) after GetSystemTime(). See https://learn.microsoft.com/en-us/archive/msdn-magazine/2004/march/implementing-a-high-resolution-time-provider-for-windows Signed-off-by: Jerry Yu <jerry.h.yu@arm.com>
This commit is contained in:
parent
38257491aa
commit
947fd3d6ea
@ -196,10 +196,13 @@ mbedtls_ms_time_t mbedtls_ms_time(void)
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
mbedtls_ms_time_t mbedtls_ms_time(void)
|
mbedtls_ms_time_t mbedtls_ms_time(void)
|
||||||
{
|
{
|
||||||
SYSTEMTIME st;
|
FILETIME ct;
|
||||||
|
mbedtls_ms_time_t current_ms;
|
||||||
|
|
||||||
GetSystemTime(&st);
|
GetSystemTimeAsFileTime(&ct);
|
||||||
return time(NULL)*1000LL + st.wMilliseconds;
|
current_ms = ((mbedtls_ms_time_t) ct.dwLowDateTime +
|
||||||
|
((mbedtls_ms_time_t) (ct.dwHighDateTime) << 32LL))/10;
|
||||||
|
return current_ms;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#error "No mbedtls_ms_time available"
|
#error "No mbedtls_ms_time available"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user