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
1 changed files with 6 additions and 3 deletions
|
@ -196,10 +196,13 @@ mbedtls_ms_time_t mbedtls_ms_time(void)
|
|||
#include <windows.h>
|
||||
mbedtls_ms_time_t mbedtls_ms_time(void)
|
||||
{
|
||||
SYSTEMTIME st;
|
||||
FILETIME ct;
|
||||
mbedtls_ms_time_t current_ms;
|
||||
|
||||
GetSystemTime(&st);
|
||||
return time(NULL)*1000LL + st.wMilliseconds;
|
||||
GetSystemTimeAsFileTime(&ct);
|
||||
current_ms = ((mbedtls_ms_time_t) ct.dwLowDateTime +
|
||||
((mbedtls_ms_time_t) (ct.dwHighDateTime) << 32LL))/10;
|
||||
return current_ms;
|
||||
}
|
||||
#else
|
||||
#error "No mbedtls_ms_time available"
|
||||
|
|
Loading…
Reference in a new issue