blob: e3a2cda3b9fe89b97519d8cd64541543b676bd2a [file] [log] [blame]
Junxiao Shi61c5ef32014-01-24 20:59:30 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Named Data Networking Project
4 * See COPYING for copyright and distribution information.
5 */
6
7#include "time.hpp"
8#include <time.h>
9#include <stdexcept>
10#include <sys/time.h>
11
12namespace ndn {
13namespace time {
14
15Point
16now()
17{
18#ifdef HAVE_RT
19
20 struct timespec t;
21 int res = clock_gettime(CLOCK_MONOTONIC, &t);
22
23 if (res == -1) {
24 throw std::runtime_error("clock_gettime");
25 }
26
27 return t.tv_sec * 1000000000 + t.tv_nsec;
28
29#else
30 // fallback to wall clock time
31
32 struct timeval tv;
33 int res = gettimeofday(&tv, 0);
34
35 if (res == -1) {
36 throw std::runtime_error("gettimeofday");
37 }
38
39 return tv.tv_sec * 1000000000 + tv.tv_usec * 1000;
40
41#endif
42}
43
44} // namespace time
45} // namespace ndn