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