Skip to content
Snippets Groups Projects
Verified Commit c998b3ae authored by Francois Keith's avatar Francois Keith Committed by Justin Carpentier
Browse files

Add implementation of gettimeofday for windows

parent fa5018cd
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,33 @@
#ifndef __pinocchio_utils_timer_hpp__
#define __pinocchio_utils_timer_hpp__
#ifdef WIN32
#include <Windows.h>
#include <stdint.h> // portable: uint64_t MSVC: __int64
int gettimeofday(struct timeval* tp, struct timezone* tzp)
{
// Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's
// This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC)
// until 00:00:00 January 1, 1970
static const uint64_t EPOCH = ((uint64_t)116444736000000000ULL);
SYSTEMTIME system_time;
FILETIME file_time;
uint64_t time;
GetSystemTime(&system_time);
SystemTimeToFileTime(&system_time, &file_time);
time = ((uint64_t)file_time.dwLowDateTime);
time += ((uint64_t)file_time.dwHighDateTime) << 32;
tp->tv_sec = (long)((time - EPOCH) / 10000000L);
tp->tv_usec = (long)(system_time.wMilliseconds * 1000);
return 0;
}
#else
#include <sys/time.h>
#endif
#include <iostream>
#include <stack>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment