Skip to content

Commit

Permalink
maint: Replace usage of folly in clock.hpp (#1448)
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Jerphanion <[email protected]>
Co-authored-by: William Dealtry <[email protected]>
  • Loading branch information
jjerphan and willdealtry committed Apr 25, 2024
1 parent 504636f commit 8cb133f
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions cpp/arcticdb/util/clock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,43 @@

#include <arcticdb/entity/types.hpp>

#include <folly/ClockGettimeWrappers.h>
#include <folly/portability/Time.h>
#ifndef CLOCK_REALTIME_COARSE
#include <cstdint>
#if defined(_WIN32)
#include <chrono>
#elif defined(__linux__)
#include <time.h>
#elif defined(__APPLE__)
#include <mach/mach_time.h>
#endif


namespace arcticdb::util {

class SysClock {
public:
static entity::timestamp nanos_since_epoch() {
return (*folly::chrono::clock_gettime_ns)(CLOCK_REALTIME);
}
#if defined(_WIN32) || defined(__APPLE__)
static entity::timestamp coarse_nanos_since_epoch() {
auto t = std::chrono::system_clock::now();
return std::chrono::duration_cast<std::chrono::nanoseconds>(t.time_since_epoch()).count();
auto now = std::chrono::system_clock::now();
auto now_ns = std::chrono::time_point_cast<std::chrono::nanoseconds>(now);
return now_ns.time_since_epoch().count();
}
#else
static entity::timestamp coarse_nanos_since_epoch() {
return (*folly::chrono::clock_gettime_ns)(CLOCK_REALTIME_COARSE);
}
#if defined(__linux__)
timespec ts;
clock_gettime(CLOCK_REALTIME_COARSE, &ts);
return static_cast<uint64_t>(ts.tv_sec) * 1000000000LL + ts.tv_nsec;
#elif defined(_WIN32)
return nanos_since_epoch();
#elif defined(__APPLE__)
static mach_timebase_info_data_t info = {0, 0};
if (info.denom == 0) {
mach_timebase_info(&info);
}
uint64_t now = mach_absolute_time();
now *= info.numer;
now /= info.denom;
return now;
#endif
}
};


Expand Down

0 comments on commit 8cb133f

Please sign in to comment.