From 155d468c56d141d4bd053728e334e681fdac9488 Mon Sep 17 00:00:00 2001 From: Islam AbdelRahman Date: Wed, 18 Mar 2015 11:26:10 -0700 Subject: [PATCH] Using chrono as a fallback Summary: Right now if they system we are compiling on is not Linux and not Mac we will get a compilation error this diff use chrono as a fallback when we are compiling on something other than Linux/FreeBSD/Mac Test Plan: compile on CentOS/FreeBSD ./db_test (still running) Reviewers: igor Reviewed By: igor Subscribers: dhruba Differential Revision: https://reviews.facebook.net/D35277 --- util/env_posix.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/util/env_posix.cc b/util/env_posix.cc index 54f30c4eb..329c48e95 100644 --- a/util/env_posix.cc +++ b/util/env_posix.cc @@ -45,10 +45,13 @@ #include "util/thread_status_updater.h" #include "util/thread_status_util.h" -// Get nano time for mach systems -#ifdef __MACH__ +// Get nano time includes +#if defined(OS_LINUX) || defined(OS_FREEBSD) +#elif defined(__MACH__) #include #include +#else +#include #endif #if !defined(TMPFS_MAGIC) @@ -1408,7 +1411,7 @@ class PosixEnv : public Env { } virtual uint64_t NowNanos() override { -#ifdef OS_LINUX +#if defined(OS_LINUX) || defined(OS_FREEBSD) struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); return static_cast(ts.tv_sec) * 1000000000 + ts.tv_nsec; @@ -1418,8 +1421,11 @@ class PosixEnv : public Env { host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); clock_get_time(cclock, &ts); mach_port_deallocate(mach_task_self(), cclock); -#endif return static_cast(ts.tv_sec) * 1000000000 + ts.tv_nsec; +#else + return std::chrono::duration_cast( + std::chrono::steady_clock::now().time_since_epoch()).count(); +#endif } virtual void SleepForMicroseconds(int micros) override { usleep(micros); }