David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 1 | /* |
| 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 Reiss | 53f18f0 | 2008-07-11 00:45:29 +0000 | [diff] [blame] | 19 | |
| 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 Luciani | b5e6221 | 2009-01-31 22:36:20 +0000 | [diff] [blame] | 32 | namespace apache { namespace thrift { namespace concurrency { |
David Reiss | 53f18f0 | 2008-07-11 00:45:29 +0000 | [diff] [blame] | 33 | |
| 34 | const 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 Luciani | b5e6221 | 2009-01-31 22:36:20 +0000 | [diff] [blame] | 55 | }}} // apache::thrift::concurrency |