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
main
Islam AbdelRahman 10 years ago
parent 81345b90f9
commit 155d468c56
  1. 14
      util/env_posix.cc

@ -45,10 +45,13 @@
#include "util/thread_status_updater.h" #include "util/thread_status_updater.h"
#include "util/thread_status_util.h" #include "util/thread_status_util.h"
// Get nano time for mach systems // Get nano time includes
#ifdef __MACH__ #if defined(OS_LINUX) || defined(OS_FREEBSD)
#elif defined(__MACH__)
#include <mach/clock.h> #include <mach/clock.h>
#include <mach/mach.h> #include <mach/mach.h>
#else
#include <chrono>
#endif #endif
#if !defined(TMPFS_MAGIC) #if !defined(TMPFS_MAGIC)
@ -1408,7 +1411,7 @@ class PosixEnv : public Env {
} }
virtual uint64_t NowNanos() override { virtual uint64_t NowNanos() override {
#ifdef OS_LINUX #if defined(OS_LINUX) || defined(OS_FREEBSD)
struct timespec ts; struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts); clock_gettime(CLOCK_MONOTONIC, &ts);
return static_cast<uint64_t>(ts.tv_sec) * 1000000000 + ts.tv_nsec; return static_cast<uint64_t>(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); host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
clock_get_time(cclock, &ts); clock_get_time(cclock, &ts);
mach_port_deallocate(mach_task_self(), cclock); mach_port_deallocate(mach_task_self(), cclock);
#endif
return static_cast<uint64_t>(ts.tv_sec) * 1000000000 + ts.tv_nsec; return static_cast<uint64_t>(ts.tv_sec) * 1000000000 + ts.tv_nsec;
#else
return std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::steady_clock::now().time_since_epoch()).count();
#endif
} }
virtual void SleepForMicroseconds(int micros) override { usleep(micros); } virtual void SleepForMicroseconds(int micros) override { usleep(micros); }

Loading…
Cancel
Save