-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b3e036e
commit fce53bb
Showing
57 changed files
with
8,002 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
///////////////////////////////////////////////////////////////////// | ||
// Project Name: [ CDX Class Library - CDX.lib ] | ||
// Source File: [ CDX High Performance Counter Implementation] | ||
// Author: [ Bil Simser - [email protected] ] | ||
// Contributions: [ Michael Rich, Jimb Esser ] | ||
// Revision: [ 2.0 ] | ||
///////////////////////////////////////////////////////////////////// | ||
|
||
#include "cdxhpc.h" | ||
|
||
|
||
///////////////////////////////////////////////////////////////////// | ||
// constructor | ||
///////////////////////////////////////////////////////////////////// | ||
CDXHPC::CDXHPC() | ||
{ | ||
// init to zero | ||
freq.QuadPart = 0; | ||
restart.QuadPart = 0; | ||
bPaused = FALSE; | ||
} | ||
|
||
///////////////////////////////////////////////////////////////////// | ||
// starts the counter | ||
///////////////////////////////////////////////////////////////////// | ||
BOOL CDXHPC::Start() | ||
{ | ||
QueryPerformanceCounter(&restart); | ||
if (!QueryPerformanceFrequency(&freq)) return FALSE; | ||
// convert it down to milliseconds | ||
freq.QuadPart /= 1000; | ||
return TRUE; | ||
} | ||
|
||
///////////////////////////////////////////////////////////////////// | ||
// returns the current # of ms since counter was started | ||
///////////////////////////////////////////////////////////////////// | ||
DWORD CDXHPC::GetValue() | ||
{ | ||
if (bPaused) | ||
return (DWORD)((paused.QuadPart - restart.QuadPart) / freq.QuadPart); | ||
LARGE_INTEGER timer; | ||
QueryPerformanceCounter(&timer); | ||
return (DWORD)((timer.QuadPart - restart.QuadPart) / freq.QuadPart); | ||
} | ||
|
||
///////////////////////////////////////////////////////////////////// | ||
// waits for a specified ms since the counter was started | ||
// note that if its already been that long since it was started | ||
// the function would exit immediately | ||
///////////////////////////////////////////////////////////////////// | ||
void CDXHPC::Wait(DWORD dwMilliSecs) | ||
{ | ||
while (TRUE) | ||
{ | ||
if (GetValue()>=dwMilliSecs) break; | ||
} | ||
} | ||
|
||
///////////////////////////////////////////////////////////////////// | ||
// waits for a specified ms after the function is called | ||
///////////////////////////////////////////////////////////////////// | ||
void CDXHPC::WaitFor(DWORD dwWaitTime) | ||
{ | ||
DWORD dwStart = GetValue(); | ||
while (TRUE) | ||
{ | ||
if (GetValue() - dwStart >= dwWaitTime) break; | ||
} | ||
} | ||
|
||
|
||
///////////////////////////////////////////////////////////////////// | ||
// resets the counter back to zero | ||
///////////////////////////////////////////////////////////////////// | ||
void CDXHPC::Reset() | ||
{ | ||
LARGE_INTEGER timer, excess; | ||
QueryPerformanceCounter(&timer); | ||
excess.QuadPart = (timer.QuadPart - restart.QuadPart) % freq.QuadPart; | ||
QueryPerformanceCounter(&restart); | ||
restart.QuadPart -= excess.QuadPart; | ||
} | ||
|
||
void CDXHPC::Pause() | ||
{ | ||
if (!bPaused) { | ||
QueryPerformanceCounter(&paused); | ||
bPaused = TRUE; | ||
} | ||
} | ||
|
||
void CDXHPC::Resume() | ||
{ | ||
if (bPaused) { | ||
LARGE_INTEGER timer; | ||
QueryPerformanceCounter(&timer); | ||
restart.QuadPart += timer.QuadPart - paused.QuadPart; | ||
bPaused = FALSE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// CDXHPC class, with additional functions - Pause and Resume added by Jimb Esser | ||
|
||
#ifndef _H_CDXHPC | ||
#define _H_CDXHPC | ||
|
||
#define WIN32_EXTRA_LEAN | ||
#include <windows.h> | ||
|
||
class CDXHPC | ||
{ | ||
public: | ||
// constructor | ||
CDXHPC(); | ||
// destructor | ||
virtual ~CDXHPC() {}; | ||
|
||
// starts the counter | ||
BOOL Start(); | ||
// returns the current # of ms since counter was started | ||
DWORD GetValue(); | ||
// waits for a specified ms since the counter was started | ||
// note that if its already been that long since it was started | ||
// the function would exit immediately | ||
void Wait(DWORD dwStopTime); | ||
// waits for a specified ms after the function is called | ||
void WaitFor(DWORD dwWaitTime); | ||
|
||
// resets the counter back to zero | ||
void Reset(); | ||
|
||
void Pause(); | ||
void Resume(); | ||
|
||
protected: | ||
// counter variables | ||
LARGE_INTEGER freq, restart, paused; | ||
BOOL bPaused; | ||
}; | ||
|
||
#endif /* #ifndef _H_CDXHPC */ |
Oops, something went wrong.