summaryrefslogtreecommitdiff
path: root/ace
diff options
context:
space:
mode:
authorbrunsch <brunsch@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-03-24 21:38:40 +0000
committerbrunsch <brunsch@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-03-24 21:38:40 +0000
commitf4a43c1fdd15cf3959132e6426b95ee3ae052d63 (patch)
tree9adfee23c6413040ece6b43f9bec6d0f61508120 /ace
parentd17b94305a2ab6d88480b4c9063ceadadaac5a24 (diff)
downloadATCD-f4a43c1fdd15cf3959132e6426b95ee3ae052d63.tar.gz
Changed the implementation of the High Resolution Timer to use
QueryPerformanceCounter instead of assembly code. The docs also say that this is MP-safe.
Diffstat (limited to 'ace')
-rw-r--r--ace/High_Res_Timer.cpp46
-rw-r--r--ace/High_Res_Timer.h9
-rw-r--r--ace/OS.i27
3 files changed, 11 insertions, 71 deletions
diff --git a/ace/High_Res_Timer.cpp b/ace/High_Res_Timer.cpp
index 9791601f274..76095a14b15 100644
--- a/ace/High_Res_Timer.cpp
+++ b/ace/High_Res_Timer.cpp
@@ -23,43 +23,6 @@ ACE_ALLOC_HOOK_DEFINE(ACE_High_Res_Timer)
# include "ace/Synch.h"
# include "ace/Object_Manager.h"
-# if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)
-
-u_long
-ACE_High_Res_Timer::get_registry_scale_factor (void)
-{
- HKEY hk;
- unsigned long speed;
- unsigned long speed_size = sizeof speed;
- unsigned long speed_type = REG_DWORD;
-
- long rc = ::RegOpenKeyEx (HKEY_LOCAL_MACHINE,
- ACE_TEXT ("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"),
- NULL,
- KEY_READ,
- &hk);
-
- if (rc != ERROR_SUCCESS)
- // Couldn't find key
- return 1;
-
- rc = ::RegQueryValueEx (hk,
- ACE_TEXT ("~MHz"),
- 0,
- &speed_type,
- (LPBYTE) &speed,
- &speed_size);
-
- ::RegCloseKey (hk);
-
- if (rc != ERROR_SUCCESS)
- // Couldn't get the value
- return 1;
-
- return speed;
-}
-# endif /*ACE_WIN32 && ! ACE_HAS_WINCE */
-
// Initialize the global_scale_factor_ to 1. The first
// ACE_High_Res_Timer instance construction will override this
// value.
@@ -96,8 +59,11 @@ ACE_High_Res_Timer::global_scale_factor ()
if (ACE_High_Res_Timer::global_scale_factor_ == 1u)
{
# if defined (ACE_WIN32)
- ACE_High_Res_Timer::global_scale_factor (
- ACE_High_Res_Timer::get_registry_scale_factor ());
+ LARGE_INTEGER freq;
+ if (::QueryPerformanceFrequency (&freq))
+ // We have a high-res timer
+ ACE_High_Res_Timer::global_scale_factor (ACE_static_cast (unsigned int,
+ freq.QuadPart / 1000000));
# elif defined (linux) && (__alpha__)
// Get the BogoMIPS from /proc. It works fine on
// Alpha and Pentium Pro. For other CPUs, it will
@@ -178,7 +144,7 @@ ACE_High_Res_Timer::calibrate (const ACE_UINT32 usec,
// The addition of 5 below rounds instead of truncates.
const ACE_UINT32 scale_factor =
- (ticks.whole () / actual_sleep.whole () + 5) /
+ (ticks.whole () / actual_sleep.whole () + 5) /
10u /* usec/100 usec */;
ACE_High_Res_Timer::global_scale_factor (scale_factor);
diff --git a/ace/High_Res_Timer.h b/ace/High_Res_Timer.h
index 6fca8eecfaa..36410c6667f 100644
--- a/ace/High_Res_Timer.h
+++ b/ace/High_Res_Timer.h
@@ -178,15 +178,6 @@ public:
// However, setting the global_scale_factor_ appropriately will
// result in the finest resolution possible.
-protected:
-
-#if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)
- static u_long get_registry_scale_factor (void);
- // This is used to find out the Mhz of the machine for the scale
- // factor. If there are any problems getting it, we just return 1
- // (the default).
-#endif /* ACE_WIN32 */
-
private:
static void hrtime_to_tv (ACE_Time_Value &tv,
const ACE_hrtime_t hrt);
diff --git a/ace/OS.i b/ace/OS.i
index 6479f0fa4f3..bdee65fef91 100644
--- a/ace/OS.i
+++ b/ace/OS.i
@@ -8661,30 +8661,13 @@ ACE_OS::gethrtime (const ACE_HRTimer_Op op)
asm volatile ("rpcc %0" : "=r" (now) : : "memory");
return now;
-#elif defined (ACE_WIN32) && defined (ACE_HAS_PENTIUM) && !defined (ACE_HAS_WINCE)
- // Issue the RDTSC assembler instruction to get the number of clock
- // ticks since system boot. RDTSC is only available on Pentiums and
- // higher. Thanks to Wayne Vucenic <wvucenic@netgate.net> for
- // pointing us to intel's RDTSC instruction. See
- // http://www.sandpile.org/80x86/rdtsc.shtml for a description of
- // the RDTSC instruction. Or see Frank van Gilluwe's "The
- // Undocumented PC" published by Addison Wesley Developers Press.
+#elif defined (ACE_WIN32) && defined (ACE_HAS_PENTIUM)
+ LARGE_INTEGER freq;
- ACE_UNUSED_ARG (op);
- unsigned long least;
- unsigned long most;
-
- __asm {
- // __asm rdtsc
- // VC++ doesn't know the opcode for rdtsc (OFh, 31h), so we'll
- // emit the opcode manually.
- __asm _emit 0xf
- __asm _emit 0x31
- __asm mov least,eax
- __asm mov most,edx
- }
+ ::QueryPerformanceCounter (&freq);
+
+ return freq.QuadPart;
- return ACE_MAKE_QWORD (least, most);
#elif defined (CHORUS)
if (op == ACE_OS::ACE_HRTIMER_GETTIME)
{