blob: c220238c9ecc14a271438cdd17704547b7c9cb69 [file] [log] [blame]
David Reiss53f18f02008-07-11 00:45:29 +00001// Copyright (c) 2006- Facebook
2// Distributed under the Thrift Software License
3//
4// See accompanying file LICENSE or visit the Thrift site at:
5// http://developers.facebook.com/thrift/
6
7#include "Util.h"
8
9#ifdef HAVE_CONFIG_H
10#include <config.h>
11#endif
12
13#if defined(HAVE_CLOCK_GETTIME)
14#include <time.h>
15#elif defined(HAVE_GETTIMEOFDAY)
16#include <sys/time.h>
17#endif // defined(HAVE_CLOCK_GETTIME)
18
T Jake Lucianib5e62212009-01-31 22:36:20 +000019namespace apache { namespace thrift { namespace concurrency {
David Reiss53f18f02008-07-11 00:45:29 +000020
21const int64_t Util::currentTime() {
22 int64_t result;
23
24#if defined(HAVE_CLOCK_GETTIME)
25 struct timespec now;
26 int ret = clock_gettime(CLOCK_REALTIME, &now);
27 assert(ret == 0);
28 toMilliseconds(result, now);
29#elif defined(HAVE_GETTIMEOFDAY)
30 struct timeval now;
31 int ret = gettimeofday(&now, NULL);
32 assert(ret == 0);
33 toMilliseconds(result, now);
34#else
35#error "No high-precision clock is available."
36#endif // defined(HAVE_CLOCK_GETTIME)
37
38 return result;
39}
40
41
T Jake Lucianib5e62212009-01-31 22:36:20 +000042}}} // apache::thrift::concurrency