Function gettimeofday

Synopsis

#include <src/easylogging++.h>

static void gettimeofday(struct timeval *tv)

Description

Cross platform gettimeofday for Windows and unix platform. This can be used to determine current microsecond.

DateTime.

@detail For unix system it uses gettimeofday(timeval*, timezone*) and for Windows, a separate implementation is provided

Parameters

[ in,out ] tv - Pointer that gets updated

Source

Lines 1154-1179 in src/easylogging++.cc. Line 1189 in src/easylogging++.h.

void DateTime::gettimeofday(struct timeval* tv) {
#if ELPP_OS_WINDOWS
  if (tv != nullptr) {
#  if ELPP_COMPILER_MSVC || defined(_MSC_EXTENSIONS)
    const unsigned __int64 delta_ = 11644473600000000Ui64;
#  else
    const unsigned __int64 delta_ = 11644473600000000ULL;
#  endif  // ELPP_COMPILER_MSVC || defined(_MSC_EXTENSIONS)
    const double secOffSet = 0.000001;
    const unsigned long usecOffSet = 1000000;
    FILETIME fileTime;
    GetSystemTimeAsFileTime(&fileTime);
    unsigned __int64 present = 0;
    present |= fileTime.dwHighDateTime;
    present = present << 32;
    present |= fileTime.dwLowDateTime;
    present /= 10;  // mic-sec
    // Subtract the difference
    present -= delta_;
    tv->tv_sec = static_cast<long>(present * secOffSet);
    tv->tv_usec = static_cast<long>(present % usecOffSet);
  }
#else
  ::gettimeofday(tv, nullptr);
#endif  // ELPP_OS_WINDOWS
}





Add Discussion

Log in to comment