Addd current_utc_time() again which got lost during merge

This commit is contained in:
Matthias Köfferlein 2018-09-09 16:51:54 +02:00
parent a543950316
commit 9544a5419b
1 changed files with 30 additions and 0 deletions

View File

@ -47,6 +47,36 @@
namespace tl
{
// -------------------------------------------------------------
void current_utc_time (struct timespec *ts)
{
#if defined(__MACH__)
clock_serv_t cclock;
mach_timespec_t mts;
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
clock_get_time(cclock, &mts);
mach_port_deallocate(mach_task_self(), cclock);
ts->tv_sec = mts.tv_sec;
ts->tv_nsec = mts.tv_nsec;
#elif defined(_MSC_VER)
FILETIME ft;
GetSystemTimeAsFileTime (&ft);
uint64_t t = (uint64_t (ft.dwHighDateTime) << (sizeof (ft.dwHighDateTime) * 8)) | uint64_t (ft.dwLowDateTime);
// t is in 100ns units
ts->tv_nsec = (t % 10000000) * 100;
ts->tv_sec = (t / 10000000);
#else
clock_gettime(CLOCK_REALTIME, ts);
#endif
}
// -------------------------------------------------------------
// Gets the current time in ms from epoch