[wpiutil] Add GetSystemTime() (#3840)

This portably gets the time in microseconds since the Unix epoch.
This commit is contained in:
Peter Johnson
2021-12-28 01:06:31 -06:00
committed by GitHub
parent 1e82595ffb
commit 5999a26fba
4 changed files with 41 additions and 3 deletions

View File

@@ -16,7 +16,7 @@
#endif
// offset in microseconds
static uint64_t zerotime() noexcept {
static uint64_t time_since_epoch() noexcept {
#ifdef _WIN32
FILETIME ft;
uint64_t tmpres = 0;
@@ -35,7 +35,7 @@ static uint64_t zerotime() noexcept {
#else
// 1-us intervals
return std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::high_resolution_clock::now().time_since_epoch())
std::chrono::system_clock::now().time_since_epoch())
.count();
#endif
}
@@ -66,7 +66,7 @@ static uint64_t update_frequency() {
}
#endif
static const uint64_t zerotime_val = zerotime();
static const uint64_t zerotime_val = time_since_epoch();
static const uint64_t offset_val = timestamp();
#ifdef _WIN32
static const uint64_t frequency_val = update_frequency();
@@ -96,6 +96,10 @@ uint64_t wpi::Now() {
return (now_impl.load())();
}
uint64_t wpi::GetSystemTime() {
return time_since_epoch();
}
extern "C" {
uint64_t WPI_NowDefault(void) {
@@ -110,4 +114,8 @@ uint64_t WPI_Now(void) {
return wpi::Now();
}
uint64_t WPI_GetSystemTime(void) {
return wpi::GetSystemTime();
}
} // extern "C"