Another checkpoint of initial cut at thread pool manager for thrift and related concurrency classes.

Added TimerManager -  I can't live without one after all.

Added Util - handy place for common time operations et al.

Initial test code


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664722 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/concurrency/Util.h b/lib/cpp/src/concurrency/Util.h
new file mode 100644
index 0000000..3ab8929
--- /dev/null
+++ b/lib/cpp/src/concurrency/Util.h
@@ -0,0 +1,67 @@
+#if !defined(_concurrency_Util_h_)
+#define _concurrency_Util_h_ 1
+
+#include <assert.h>
+#include <time.h>
+
+namespace facebook { namespace thrift { namespace concurrency { 
+
+/**  Utility methods
+
+     This class contains basic utility methods for converting time formats, and other common platform-dependent concurrency operations.
+     It should not be included in API headers for other concurrency library headers, since it will, by definition, pull in all sorts of
+     horrid platform dependent crap.  Rather it should be inluded directly in concurrency library implementation source. 
+
+     @author marc
+     @version $Id:$ */
+
+class Util {
+
+ public:
+
+  /** Converts relative timeout specified as a duration in milliseconds to a struct timespec structure
+      specifying current time plus timeout 
+
+      @param struct timespec& current time plus timeout result  
+      @param timeout time to delay in milliseconds */
+
+  static const void toAbsoluteTimespec(struct timespec& result, long long value) {
+    
+    // XXX Darwin doesn't seem to have any readily useable hi-res clock.
+    
+    time_t seconds; 
+    
+    assert(time(&seconds) != (time_t)-1);
+    
+    seconds+= (value / 1000);
+    
+    long nanoseconds = (value % 1000) * 1000000;
+    
+    result.tv_sec = seconds + (nanoseconds / 1000000000);
+    
+    result.tv_nsec = nanoseconds % 1000000000;
+  }
+
+  /** Converts absolute timespec to milliseconds from epoch */
+
+  static const void toMilliseconds(long long& result, const struct timespec& value) {
+
+    result = value.tv_sec * 1000 + value.tv_nsec * 1000000;
+  }
+
+  /** Get current time as milliseconds from epoch */
+
+  static const long long currentTime() {
+
+    time_t now;
+
+    time(&now);
+
+    return (long long)now * 1000;
+  }
+};
+
+
+}}} // facebook::thrift::concurrency
+
+#endif // !defined(_concurrency_Util_h_)