blob: 1c44937165cb8a580e42dfa3a7874d54b90a0d15 [file] [log] [blame]
David Reissea2cba82009-03-30 21:35:00 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
David Reiss53f18f02008-07-11 00:45:29 +000019
20#include "Util.h"
21
22#ifdef HAVE_CONFIG_H
23#include <config.h>
24#endif
25
26#if defined(HAVE_CLOCK_GETTIME)
27#include <time.h>
28#elif defined(HAVE_GETTIMEOFDAY)
29#include <sys/time.h>
30#endif // defined(HAVE_CLOCK_GETTIME)
31
T Jake Lucianib5e62212009-01-31 22:36:20 +000032namespace apache { namespace thrift { namespace concurrency {
David Reiss53f18f02008-07-11 00:45:29 +000033
34const int64_t Util::currentTime() {
35 int64_t result;
36
37#if defined(HAVE_CLOCK_GETTIME)
38 struct timespec now;
39 int ret = clock_gettime(CLOCK_REALTIME, &now);
40 assert(ret == 0);
41 toMilliseconds(result, now);
42#elif defined(HAVE_GETTIMEOFDAY)
43 struct timeval now;
44 int ret = gettimeofday(&now, NULL);
45 assert(ret == 0);
46 toMilliseconds(result, now);
47#else
48#error "No high-precision clock is available."
49#endif // defined(HAVE_CLOCK_GETTIME)
50
51 return result;
52}
53
54
T Jake Lucianib5e62212009-01-31 22:36:20 +000055}}} // apache::thrift::concurrency