Author: dreiss
Date: Thu Jul 10 17:45:29 2008
New Revision: 675819

URL: http://svn.apache.org/viewvc?rev=675819&view=rev
Log:
(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.

Added:
    incubator/thrift/trunk/lib/cpp/src/concurrency/Util.cpp
Modified:
    incubator/thrift/trunk/lib/cpp/Makefile.am
    incubator/thrift/trunk/lib/cpp/src/concurrency/Util.h

Modified: incubator/thrift/trunk/lib/cpp/Makefile.am
URL: 
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/cpp/Makefile.am?rev=675819&r1=675818&r2=675819&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/cpp/Makefile.am (original)
+++ incubator/thrift/trunk/lib/cpp/Makefile.am Thu Jul 10 17:45:29 2008
@@ -28,6 +28,7 @@
                        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 \

Added: incubator/thrift/trunk/lib/cpp/src/concurrency/Util.cpp
URL: 
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/cpp/src/concurrency/Util.cpp?rev=675819&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/cpp/src/concurrency/Util.cpp (added)
+++ incubator/thrift/trunk/lib/cpp/src/concurrency/Util.cpp Thu Jul 10 17:45:29 
2008
@@ -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 <config.h>
+#endif
+
+#if defined(HAVE_CLOCK_GETTIME)
+#include <time.h>
+#elif defined(HAVE_GETTIMEOFDAY)
+#include <sys/time.h>
+#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

Modified: incubator/thrift/trunk/lib/cpp/src/concurrency/Util.h
URL: 
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/cpp/src/concurrency/Util.h?rev=675819&r1=675818&r2=675819&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/cpp/src/concurrency/Util.h (original)
+++ incubator/thrift/trunk/lib/cpp/src/concurrency/Util.h Thu Jul 10 17:45:29 
2008
@@ -7,17 +7,11 @@
 #ifndef _THRIFT_CONCURRENCY_UTIL_H_
 #define _THRIFT_CONCURRENCY_UTIL_H_ 1
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 #include <assert.h>
 #include <stddef.h>
-#if defined(HAVE_CLOCK_GETTIME)
+#include <stdint.h>
 #include <time.h>
-#else // defined(HAVE_CLOCK_GETTIME)
 #include <sys/time.h>
-#endif // defined(HAVE_CLOCK_GETTIME)
 
 namespace facebook { namespace thrift { namespace concurrency {
 
@@ -86,24 +80,7 @@
   /**
    * 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


Reply via email to