You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2009/09/28 14:45:09 UTC
svn commit: r819515 - in
/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang: System.cpp
System.h
Author: tabish
Date: Mon Sep 28 12:45:09 2009
New Revision: 819515
URL: http://svn.apache.org/viewvc?rev=819515&view=rev
Log:
Remove use of APR from time Functions.
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.h
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.cpp?rev=819515&r1=819514&r2=819515&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.cpp Mon Sep 28 12:45:09 2009
@@ -23,14 +23,21 @@
#include <decaf/util/Date.h>
#include <decaf/util/StringTokenizer.h>
#include <decaf/util/StlMap.h>
+#include <decaf/util/concurrent/TimeUnit.h>
#include <apr.h>
#include <apr_errno.h>
#include <apr_env.h>
#include <apr_time.h>
-#if APR_HAVE_UNISTD_H
+#if HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#if HAVE_UNISTD_H
#include <unistd.h>
#endif
+#ifdef HAVE_TIME_H
+#include <time.h>
+#endif
#include <cstdlib>
@@ -38,6 +45,7 @@
using namespace decaf;
using namespace decaf::lang;
using namespace decaf::util;
+using namespace decaf::util::concurrent;
using namespace decaf::internal;
using namespace decaf::lang::exceptions;
@@ -124,12 +132,53 @@
////////////////////////////////////////////////////////////////////////////////
long long System::currentTimeMillis() {
- return apr_time_now() / 1000;
+
+#ifdef _WIN32
+
+ /* Number of micro-seconds between the beginning of the Windows epoch
+ * (Jan. 1, 1601) and the Unix epoch (Jan. 1, 1970)
+ */
+ static const unsigned long long DELTA_EPOCH_IN_USEC = 116444736000000000ULL;
+
+ unsigned long long time = 0;
+ ::GetSystemTimeAsFileTime( (FILETIME*)&time );
+ return ( time - DELTA_EPOCH_IN_USEC ) / 10000;
+
+#else
+
+ struct timeval tv;
+ gettimeofday( &tv, NULL );
+ return ( ( (long long)tv.tv_sec * 1000000 ) + tv.tv_usec ) / 1000;
+
+#endif
}
////////////////////////////////////////////////////////////////////////////////
long long System::nanoTime() {
- return apr_time_now() * 1000;
+
+#ifdef _WIN32
+
+ LARGE_INTEGER freq, i, multiplier;
+ long long result;
+
+ if( !::QueryPerformanceFrequency( &freq ) ) {
+ return ::GetTickCount();
+ }
+
+ multiplier.QuadPart = freq.QuadPart / 1000000;
+
+ ::QueryPerformanceCounter( &i );
+ result = i.QuadPart / multiplier.QuadPart;
+
+ return result * 1000;
+
+#else
+
+ struct timeval tv;
+ gettimeofday( &tv, NULL );
+ return ( ( (long long)tv.tv_sec * 1000000 ) + tv.tv_usec ) * 1000;
+
+#endif
}
////////////////////////////////////////////////////////////////////////////////
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.h?rev=819515&r1=819514&r2=819515&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.h Mon Sep 28 12:45:09 2009
@@ -72,14 +72,23 @@
throw ( lang::Exception );
/**
- * @returns the current system time in Milliseconds
+ * Returns the current time in milliseconds. Note that while the unit of time of
+ * the return value is a millisecond, the granularity of the value depends on the
+ * underlying operating system and may be larger. For example, many operating
+ * systems measure time in units of tens of milliseconds.
+ *
+ * See the description of the class Date for a discussion of slight discrepancies
+ * that may arise between "computer time" and coordinated universal time (UTC).
+ *
+ * @returns the difference, measured in milliseconds, between the current time
+ * and midnight, January 1, 1970 UTC.
*/
static long long currentTimeMillis();
/**
* Returns the current value of the most precise available system timer, in
* nanoseconds.
- * <p>
+ *
* This method can only be used to measure elapsed time and is not related to
* any other notion of system or wall-clock time. The value returned represents
* nanoseconds since some fixed but arbitrary time (perhaps in the future, so
@@ -88,13 +97,12 @@
* values change. Differences in successive calls that span greater than
* approximately 292 years (263 nanoseconds) will not accurately compute elapsed
* time due to numerical overflow.
- * <p>
+ *
* For example, to measure how long some code takes to execute:
- * <p>
+ *
* long long startTime = System::nanoTime();
* // ... the code being measured ...
* long long estimatedTime = System::nanoTime() - startTime;
- * <p>
*
* @returns
* The current value of the system timer, in nanoseconds.