diff options
author | irfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-07-07 22:19:58 +0000 |
---|---|---|
committer | irfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-07-07 22:19:58 +0000 |
commit | c5f1347e390f1bc1c92c1b6bd17a73c7a1d8c099 (patch) | |
tree | e52d2e277794ce25ee32ad5b22084ac9653b2fcb | |
parent | 1feb58ca434b415d145b62c3a9704d31a912cf77 (diff) | |
download | ATCD-c5f1347e390f1bc1c92c1b6bd17a73c7a1d8c099.tar.gz |
*** empty log message ***
-rw-r--r-- | ChangeLog-97a | 9 | ||||
-rw-r--r-- | ace/High_Res_Timer.cpp | 56 | ||||
-rw-r--r-- | ace/High_Res_Timer.h | 7 |
3 files changed, 41 insertions, 31 deletions
diff --git a/ChangeLog-97a b/ChangeLog-97a index 0563ae1c093..6a4f86c626c 100644 --- a/ChangeLog-97a +++ b/ChangeLog-97a @@ -1,3 +1,12 @@ +Mon Jul 07 17:01:47 1997 <irfan@TWOSTEP> + + * ace/High_Res_Timer.cpp (get_registry_scale_factor): Rewrote some + of the code to make things more stable. We may need to rewrite + some parts so that the static variable is not initialized if we + are not using Timers. Currently, everyone using ACE on Win32 + pays the price for running this code, irrespective of whether + they are using Timers or not. + Thu Jul 3 20:36:19 1997 Nanbor Wang <nw1@cumbia.cs.wustl.edu> * performance-tests/Misc/childbirth_time.cpp: Changed the diff --git a/ace/High_Res_Timer.cpp b/ace/High_Res_Timer.cpp index e1d256ef809..a7e1ab7029e 100644 --- a/ace/High_Res_Timer.cpp +++ b/ace/High_Res_Timer.cpp @@ -14,56 +14,50 @@ ACE_ALLOC_HOOK_DEFINE(ACE_High_Res_Timer) // by zero errors. #if defined (ACE_WIN32) -// 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) +u_long +ACE_High_Res_Timer::get_registry_scale_factor (void) { HKEY hk; - DWORD buf_type = REG_DWORD; - DWORD buf_len = 10; - TCHAR *buffer = new TCHAR[10]; + unsigned long speed; + unsigned long speed_size = sizeof speed; + unsigned long speed_type = REG_DWORD; + + long rc = ::RegOpenKeyEx (HKEY_LOCAL_MACHINE, + __TEXT ("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"), + NULL, + KEY_READ, + &hk); - 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); + rc = ::RegQueryValueEx (hk, + __TEXT ("~MHz"), + 0, + &speed_type, + (LPBYTE) &speed, + &speed_size); + + ::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; + return speed; } -u_long ACE_High_Res_Timer::global_scale_factor_ = get_registry_scale_factor (); +/* static */ +u_long ACE_High_Res_Timer::global_scale_factor_ = ACE_High_Res_Timer::get_registry_scale_factor (); #else + // A scale_factor of 1000 converts nanosecond ticks to microseconds. // That is, on these platforms, 1 tick == 1 nanosecond. +/* static */ u_long ACE_High_Res_Timer::global_scale_factor_ = 1000; + #endif /* ACE_WIN32 */ void diff --git a/ace/High_Res_Timer.h b/ace/High_Res_Timer.h index b7125335c90..efb67ad1f74 100644 --- a/ace/High_Res_Timer.h +++ b/ace/High_Res_Timer.h @@ -136,6 +136,13 @@ public: // However, setting the global_scale_factor_ appropriately will // result in the finest resolution possible. +protected: + + 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). + private: static void hrtime_to_tv (ACE_Time_Value &tv, ACE_hrtime_t hrt); |