From 4ba52ddb707cbb025eef1740e79ba8d166c9ecc6 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Thu, 17 Nov 2011 08:47:11 +0000 Subject: [PATCH] 2011-11-17 09:46 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/contrib/hbwin/hbwapi.h * harbour/contrib/hbwin/wapi_winbase.c * harbour/contrib/hbwin/hbwin.hbx + added to new WIN API wrappers: WAPI_QueryPerformanceCounter( @nCounter ) -> WAPI_QueryPerformanceFrequency( @nFrequency ) -> Warning: read in MSDN about above functions and possible interactions with multi CPU machines. * harbour/contrib/hbwin/win_misc.c * harbour/contrib/hbwin/hbwin.hbx + added new function which converts QueryPerformance counters to seconds: WIN_QPCOUNTER2SEC( nCounter ) -> I suggest to use it to convert difference between two calls to WAPI_QueryPerformanceCounter(), i.e.: WAPI_QueryPerformanceCounter( @nCounterStart ) [...] WAPI_QueryPerformanceCounter( @nCounterEnd ) ? "total time:", ; WIN_QPCOUNTER2SEC( nCounterEnd - nCounterStart ), "sec." --- harbour/ChangeLog | 23 +++++++++++++++++++++++ harbour/contrib/hbwin/hbwapi.h | 8 ++++++++ harbour/contrib/hbwin/hbwin.hbx | 3 +++ harbour/contrib/hbwin/wapi_winbase.c | 19 +++++++++++++++++++ harbour/contrib/hbwin/win_misc.c | 18 ++++++++++++++++++ 5 files changed, 71 insertions(+) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 42ad5a3276..5b19cb0fe5 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,29 @@ The license applies to all entries newer than 2009-04-28. */ +2011-11-17 09:46 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/contrib/hbwin/hbwapi.h + * harbour/contrib/hbwin/wapi_winbase.c + * harbour/contrib/hbwin/hbwin.hbx + + added to new WIN API wrappers: + WAPI_QueryPerformanceCounter( @nCounter ) -> + WAPI_QueryPerformanceFrequency( @nFrequency ) -> + Warning: read in MSDN about above functions and possible + interactions with multi CPU machines. + + * harbour/contrib/hbwin/win_misc.c + * harbour/contrib/hbwin/hbwin.hbx + + added new function which converts QueryPerformance counters + to seconds: + WIN_QPCOUNTER2SEC( nCounter ) -> + I suggest to use it to convert difference between two calls + to WAPI_QueryPerformanceCounter(), i.e.: + WAPI_QueryPerformanceCounter( @nCounterStart ) + [...] + WAPI_QueryPerformanceCounter( @nCounterEnd ) + ? "total time:", ; + WIN_QPCOUNTER2SEC( nCounterEnd - nCounterStart ), "sec." + 2011-11-15 23:28 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/src/rtl/hbproces.c * added workaround for missing chroot() in OpenWatcom 1.9 linux libraries diff --git a/harbour/contrib/hbwin/hbwapi.h b/harbour/contrib/hbwin/hbwapi.h index 727b659613..106eb57f63 100644 --- a/harbour/contrib/hbwin/hbwapi.h +++ b/harbour/contrib/hbwin/hbwapi.h @@ -124,6 +124,14 @@ # endif #endif +#if defined( __BORLANDC__ ) +# define HBWAPI_GET_LARGEUINT( v ) ( ( HB_MAXUINT ) (v).u.LowPart | \ + ( ( HB_MAXUINT ) (v).u.HighPart << 32 ) ) +#else +# define HBWAPI_GET_LARGEUINT( v ) ( ( HB_MAXUINT ) (v).LowPart | \ + ( ( HB_MAXUINT ) (v).HighPart << 32 ) ) +#endif + HB_EXTERN_BEGIN /* Intentionally not used HB_EXPORT. These are UNICODE setting dependent functions, diff --git a/harbour/contrib/hbwin/hbwin.hbx b/harbour/contrib/hbwin/hbwin.hbx index 310fff95c5..d21062f8c5 100644 --- a/harbour/contrib/hbwin/hbwin.hbx +++ b/harbour/contrib/hbwin/hbwin.hbx @@ -145,6 +145,8 @@ DYNAMIC WAPI_MULDIV DYNAMIC WAPI_OPENMUTEX DYNAMIC WAPI_OUTPUTDEBUGSTRING DYNAMIC WAPI_PLAYSOUND +DYNAMIC WAPI_QUERYPERFORMANCECOUNTER +DYNAMIC WAPI_QUERYPERFORMANCEFREQUENCY DYNAMIC WAPI_RECTANGLE DYNAMIC WAPI_RELEASEMUTEX DYNAMIC WAPI_REMOVEFONTRESOURCE @@ -372,6 +374,7 @@ DYNAMIC WIN_PRINTERSETDEFAULT DYNAMIC WIN_PRINTERSTATUS DYNAMIC WIN_PRINTFILERAW DYNAMIC WIN_PRN +DYNAMIC WIN_QPCOUNTER2SEC DYNAMIC WIN_RECTANGLE DYNAMIC WIN_REGCLOSEKEY DYNAMIC WIN_REGCREATEKEYEX diff --git a/harbour/contrib/hbwin/wapi_winbase.c b/harbour/contrib/hbwin/wapi_winbase.c index 9109b6d2cf..4090cbd995 100644 --- a/harbour/contrib/hbwin/wapi_winbase.c +++ b/harbour/contrib/hbwin/wapi_winbase.c @@ -452,3 +452,22 @@ HB_FUNC( WAPI_GETWINDOWSDIRECTORY ) } #endif } + + +HB_FUNC( WAPI_QUERYPERFORMANCECOUNTER ) +{ + LARGE_INTEGER counter; + BOOL result = QueryPerformanceCounter( &counter ); + if( result ) + hb_stornint( HBWAPI_GET_LARGEUINT( counter ), 1 ); + hb_retl( result != 0 ); +} + +HB_FUNC( WAPI_QUERYPERFORMANCEFREQUENCY ) +{ + LARGE_INTEGER frequency; + BOOL result = QueryPerformanceFrequency( &frequency ); + if( result ) + hb_stornint( HBWAPI_GET_LARGEUINT( frequency ), 1 ); + hb_retl( result != 0 ); +} diff --git a/harbour/contrib/hbwin/win_misc.c b/harbour/contrib/hbwin/win_misc.c index a873c3a500..8223cb9464 100644 --- a/harbour/contrib/hbwin/win_misc.c +++ b/harbour/contrib/hbwin/win_misc.c @@ -62,6 +62,7 @@ */ #include "hbwin.h" +#include "hbwapi.h" #include "hbapiitm.h" #ifndef QS_ALLPOSTMESSAGE @@ -312,3 +313,20 @@ HB_FUNC( WIN_SYSREFRESH ) CloseHandle( hDummyEvent ); hb_retni( 0 ); } + +HB_FUNC( WIN_QPCOUNTER2SEC ) +{ + static HB_MAXDBL s_dFrequence = 0; + + if( s_dFrequence == 0 ) + { + LARGE_INTEGER frequency; + if( !QueryPerformanceFrequency( &frequency ) ) + { + hb_retnd( 0 ); + return; + } + s_dFrequence = ( HB_MAXDBL ) HBWAPI_GET_LARGEUINT( frequency ); + } + hb_retnd( ( HB_MAXDBL ) hb_parnint( 1 ) / s_dFrequence ); +}