diff options
author | brunsch <brunsch@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-07-02 21:21:24 +0000 |
---|---|---|
committer | brunsch <brunsch@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-07-02 21:21:24 +0000 |
commit | 2c5e0de511f92ea600cb75478407a79aaec796c9 (patch) | |
tree | ab6bb8ba50fd01c460f8e20c0263aa66acce75c9 /ace/High_Res_Timer.cpp | |
parent | d5f474f6c163fec7927fc76ac3bed7eb7cea6c01 (diff) | |
download | ATCD-2c5e0de511f92ea600cb75478407a79aaec796c9.tar.gz |
Added functionality to High Res Timers to get the speed of the computer
from the registry under NT.
Diffstat (limited to 'ace/High_Res_Timer.cpp')
-rw-r--r-- | ace/High_Res_Timer.cpp | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/ace/High_Res_Timer.cpp b/ace/High_Res_Timer.cpp index 78d504fc186..15e53f5bda3 100644 --- a/ace/High_Res_Timer.cpp +++ b/ace/High_Res_Timer.cpp @@ -1,5 +1,4 @@ // High_Res_Timer.cpp -// $Id$ #define ACE_BUILD_DLL #include "ace/High_Res_Timer.h" @@ -14,7 +13,53 @@ ACE_ALLOC_HOOK_DEFINE(ACE_High_Res_Timer) // ACE_OS::gethrtime. We'll still set this to one to prevent division // by zero errors. #if defined (ACE_WIN32) -u_long ACE_High_Res_Timer::global_scale_factor_ = 1; + +// 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). +static u_long get_registry_scale_factor (void) +{ + HKEY hk; + DWORD buf_type = REG_DWORD; + DWORD buf_len = 10; + TCHAR *buffer = new TCHAR[10]; + + LONG rc = RegOpenKeyEx (HKEY_LOCAL_MACHINE, + TEXT("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"), + NULL, + KEY_READ, + &hk); + + if (rc != ERROR_SUCCESS) + { + // Couldn't find key + delete buffer; + return 1; + } + + + rc = RegQueryValueEx (hk, + TEXT("~MHz"), + 0, + &buf_type, + (unsigned char *) buffer, + &buf_len); + + RegCloseKey (hk); + + if (rc != ERROR_SUCCESS) + { + // Couldn't get the value + delete buffer; + return 1; + } + + u_long mhz = (DWORD (*buffer) & 0xFF); + delete buffer; + return mhz; +} + +u_long ACE_High_Res_Timer::global_scale_factor_ = get_registry_scale_factor (); + #else // A scale_factor of 1000 converts nanosecond ticks to microseconds. // That is, on these platforms, 1 tick == 1 nanosecond. |