From: David Reiss Date: Fri, 11 Jul 2008 00:45:29 +0000 (+0000) Subject: (THRIFT-69) Fix Util::currentTime for use in applications. X-Git-Tag: 0.2.0~478 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=53f18f01bea79d373d0bb1138b67c03e42f4143c;p=common%2Fthrift.git (THRIFT-69) Fix Util::currentTime for use in applications. This function didn't work properly when used outside of the Thrift library because config.h isn't available. This patch fixes the issue by moving the function definition into the library. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@675819 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/lib/cpp/Makefile.am b/lib/cpp/Makefile.am index 5ba3f64a..96e44e8c 100644 --- a/lib/cpp/Makefile.am +++ b/lib/cpp/Makefile.am @@ -28,6 +28,7 @@ libthrift_la_SOURCES = src/Thrift.cpp \ src/concurrency/PosixThreadFactory.cpp \ src/concurrency/ThreadManager.cpp \ src/concurrency/TimerManager.cpp \ + src/concurrency/Util.cpp \ src/protocol/TBinaryProtocol.cpp \ src/protocol/TDebugProtocol.cpp \ src/protocol/TDenseProtocol.cpp \ diff --git a/lib/cpp/src/concurrency/Util.cpp b/lib/cpp/src/concurrency/Util.cpp new file mode 100644 index 00000000..eeee0e57 --- /dev/null +++ b/lib/cpp/src/concurrency/Util.cpp @@ -0,0 +1,42 @@ +// Copyright (c) 2006- Facebook +// Distributed under the Thrift Software License +// +// See accompanying file LICENSE or visit the Thrift site at: +// http://developers.facebook.com/thrift/ + +#include "Util.h" + +#ifdef HAVE_CONFIG_H +#include +#endif + +#if defined(HAVE_CLOCK_GETTIME) +#include +#elif defined(HAVE_GETTIMEOFDAY) +#include +#endif // defined(HAVE_CLOCK_GETTIME) + +namespace facebook { namespace thrift { namespace concurrency { + +const int64_t Util::currentTime() { + int64_t result; + +#if defined(HAVE_CLOCK_GETTIME) + struct timespec now; + int ret = clock_gettime(CLOCK_REALTIME, &now); + assert(ret == 0); + toMilliseconds(result, now); +#elif defined(HAVE_GETTIMEOFDAY) + struct timeval now; + int ret = gettimeofday(&now, NULL); + assert(ret == 0); + toMilliseconds(result, now); +#else +#error "No high-precision clock is available." +#endif // defined(HAVE_CLOCK_GETTIME) + + return result; +} + + +}}} // facebook::thrift::concurrency diff --git a/lib/cpp/src/concurrency/Util.h b/lib/cpp/src/concurrency/Util.h index 4031be09..483d14a5 100644 --- a/lib/cpp/src/concurrency/Util.h +++ b/lib/cpp/src/concurrency/Util.h @@ -7,17 +7,11 @@ #ifndef _THRIFT_CONCURRENCY_UTIL_H_ #define _THRIFT_CONCURRENCY_UTIL_H_ 1 -#ifdef HAVE_CONFIG_H -#include -#endif - #include #include -#if defined(HAVE_CLOCK_GETTIME) +#include #include -#else // defined(HAVE_CLOCK_GETTIME) #include -#endif // defined(HAVE_CLOCK_GETTIME) namespace facebook { namespace thrift { namespace concurrency { @@ -86,24 +80,7 @@ class Util { /** * Get current time as milliseconds from epoch */ - static const int64_t currentTime() { - int64_t result; - -#if defined(HAVE_CLOCK_GETTIME) - struct timespec now; - int ret = clock_gettime(CLOCK_REALTIME, &now); - assert(ret == 0); - toMilliseconds(result, now); -#elif defined(HAVE_GETTIMEOFDAY) - struct timeval now; - int ret = gettimeofday(&now, NULL); - assert(ret == 0); - toMilliseconds(result, now); -#endif // defined(HAVE_GETTIMEDAY) - - return result; - } - + static const int64_t currentTime(); }; }}} // facebook::thrift::concurrency