autoconf/automake/libtool-ized thrift cpp bits:
    Fixed to build on solaris.
    Used clock_gettime() where available
    Fixed rounding of time to ms

			       


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664733 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/concurrency/Util.h b/lib/cpp/src/concurrency/Util.h
index 8467a2c..6e8891d 100644
--- a/lib/cpp/src/concurrency/Util.h
+++ b/lib/cpp/src/concurrency/Util.h
@@ -1,6 +1,8 @@
 #if !defined(_concurrency_Util_h_)
 #define _concurrency_Util_h_ 1
 
+#include <config.h>
+
 #include <assert.h>
 #include <stddef.h>
 #include <sys/time.h>
@@ -18,6 +20,12 @@
 
 class Util {
 
+  static const long long NS_PER_S = 1000000000LL;
+
+  static const long long MS_PER_S = 1000LL;
+
+  static const long long NS_PER_MS = 1000000LL;
+
  public:
 
   /** Converts timespec to milliseconds
@@ -26,28 +34,39 @@
       @param time or duration in milliseconds */
 
   static void toTimespec(struct timespec& result, long long value) {
+
+    result.tv_sec = value / MS_PER_S; // ms to s
     
-    result.tv_sec = value / 1000; // ms to s
-    
-    result.tv_nsec = (value % 1000) * 1000000; // ms to ns
+    result.tv_nsec = (value % MS_PER_S) * NS_PER_MS; // ms to ns
   }
 
   /** Converts timespec to milliseconds */
 
   static const void toMilliseconds(long long& result, const struct timespec& value) {
 
-    result = value.tv_sec * 1000 + value.tv_nsec / 1000000;
+    result = (value.tv_sec * MS_PER_S) + (value.tv_nsec / NS_PER_MS) + (value.tv_nsec % NS_PER_MS >= 500000 ? 1 : 0) ;
   }
 
   /** Get current time as milliseconds from epoch */
 
   static const long long currentTime() {
 
+#if defined(HAVE_CLOCK_GETTIME)
+
+    struct timespec now;
+
+    assert(clock_gettime(&now, NULL) == 0);
+
+    return = (now.tv_sec * MS_PER_S) + (now.tv_nsec / NS_PER_MS) + (now.tv_nsec % NS_PER_MS >= 500000 ? 1 : 0) ;
+
+#elif defined(HAVE_GETTIMEOFDAY)
+
     struct timeval now;
 
     assert(gettimeofday(&now, NULL) == 0);
 
-    return ((long long)now.tv_sec) * 1000LL + now.tv_usec / 1000;
+    return (((long long)now.tv_sec) * MS_PER_S) + (now.tv_usec / MS_PER_S) + (now.tv_usec % MS_PER_S >= 500 ? 1 : 0);
+#endif // defined(HAVE_GETTIMEDAY)
   }
 };