Simple cross-platform Timer interface. Timer can be used for more accurate delay/sleep statement (1 ms accuracy), and for creating a periodic timed event with high accuracy.
More...
#include <timer.h>
List of all members.
Classes |
class | Callback |
| Callback interface for registering for Timer Events. Overload the ProcessTimerEvent method, and register with a Timer. More...
|
Public Member Functions |
| Timer () |
| Constructor.
|
| ~Timer () |
| Destructor.
|
int | Start (const double frequencyHz, const double hptThresholdHz=50) |
| Starts periodic timing event/function call.
|
void | Stop () |
| Stops periodic timer events.
|
bool | RegisterTimerEvent (Callback *timerCallback) |
| Add a pointer to a Timer::Callback object to use for generating Timer events.
|
bool | RegisterTimerEvent (void(*func)(void *args), void *fargs) |
| Add a pointer to a function to use for generating Timer events.
|
void | RemoveTimerEvent (Callback *timerCallback) |
| Remove a Timer::Callback object to used for generating Timer events.
|
void | RemoveTimerEvent (void(*func)(void *args), void *fargs) |
| Remove pointer to a function to use for generating Timer events.
|
bool | IsActive () const |
bool | IsShuttingDown () const |
void | TriggerEvents () |
| When called this method generates timer event callbacks.
|
double | GetFrequency () const |
bool | ChangeFrequency (const double frequencyHz, const double hptThresholdHz=50) |
| Method used to try change timer frequency as on the fly.
|
void | SetName (const std::string &name) |
Static Public Member Functions |
static double | GetTimeMs () |
static double | GetTimeSeconds () |
static void | Pause (const unsigned int ms) |
| Performs a blocking-pause for the set period of time in milliseconds. This method has 1ms accuracy (but is more computationally expensive in Windows).
|
Detailed Description
Simple cross-platform Timer interface. Timer can be used for more accurate delay/sleep statement (1 ms accuracy), and for creating a periodic timed event with high accuracy.
The Timer class has some static method for getting the current system time. This time is relative to when the system turned on in Windows, and is UTC time in Linux. Therefore, only use the GetTime methods in this class when you require 1ms timing information in multiple environments.
The Timer class can start a periodic event with 1ms accuracy using callback interfaces or function callbacks.
Definition at line 71 of file timer.h.
Constructor & Destructor Documentation
Member Function Documentation
bool Timer::ChangeFrequency |
( |
const double |
frequencyHz, |
|
|
const double |
hptThresholdHz = 50 |
|
) |
| |
Method used to try change timer frequency as on the fly.
In Windows, if the new frequency is greather >= to hptThresholdHz, than the timer will be stopped so a new HPT can be created. In all other cases the update time is changed on the fly.
- Parameters:
-
[in] | frequencyHz | How often to generate periodic events in Hz. |
[in] | hptThresholdHz | This parameter has no affect in Linux. However in Windows, it will determine whether or not to use the Windows High Performance Timer (HPT). |
- Returns:
- True on success, false on failure.
Definition at line 606 of file timer.cpp.
double Timer::GetFrequency |
( |
) |
const |
double Timer::GetTimeMs |
( |
) |
[static] |
- Returns:
- The current time since the system booted in milliseconds with an accuracy of 1ms. 0 is returned if precision timer is not supported in hardware.
Definition at line 401 of file timer.cpp.
double Timer::GetTimeSeconds |
( |
) |
[static] |
- Returns:
- The current time since the system booted in seconds with an accuracy of 1ms. In Windows, if the HPT is not supported by hardware than UTC time is returned which has an accuracy of <= 15ms.
Definition at line 445 of file timer.cpp.
bool CxUtils::Timer::IsActive |
( |
) |
const [inline] |
bool CxUtils::Timer::IsShuttingDown |
( |
) |
const [inline] |
void Timer::Pause |
( |
const unsigned int |
ms ) |
[static] |
Performs a blocking-pause for the set period of time in milliseconds. This method has 1ms accuracy (but is more computationally expensive in Windows).
- Parameters:
-
[in] | ms | The time to pause in milliseconds. |
Definition at line 361 of file timer.cpp.
bool Timer::RegisterTimerEvent |
( |
void(*)(void *args) |
func, |
|
|
void * |
fargs |
|
) |
| |
Add a pointer to a function to use for generating Timer events.
- Parameters:
-
[in] | func | Function callback to used for timer events. |
[in] | fargs | Pointer to arguments to pass to function callback. |
- Returns:
- True on success, false on failure.
Definition at line 294 of file timer.cpp.
Add a pointer to a Timer::Callback object to use for generating Timer events.
- Parameters:
-
[in] | timerCallback | Callback pointer to run based on Timer frequency. |
- Returns:
- True on success, false on failure.
Definition at line 267 of file timer.cpp.
void Timer::RemoveTimerEvent |
( |
void(*)(void *args) |
func, |
|
|
void * |
fargs |
|
) |
| |
Remove pointer to a function to use for generating Timer events.
- Parameters:
-
[in] | func | Function callback to used for timer events. |
[in] | fargs | Pointer to arguments to pass to function callback. |
Definition at line 334 of file timer.cpp.
void CxUtils::Timer::SetName |
( |
const std::string & |
name ) |
[inline] |
int Timer::Start |
( |
const double |
frequencyHz, |
|
|
const double |
hptThresholdHz = 50 |
|
) |
| |
Starts periodic timing event/function call.
The threshold parameter is used to indicate if the Windows High Performance Timer (HPT) is used in Windows. In Linux, the parameter does nothing. The HPT has 1ms accuracy, but can be computationally expensive for your program. If not used, then a thread is used to generated periodic events which has <= 15ms of accuracy, but has little CPU cost. If frequency is greater than hptThresholdHz, the HPT is used. The default value for the hptThresholdHz is 50 Hz.
- Parameters:
-
[in] | frequencyHz | How often to generate periodic events in Hz. |
[in] | hptThresholdHz | This parameter has no affect in Linux. However in Windows, it will determine whether or not to use the Windows High Performance Timer (HPT). |
- Returns:
- 1 if timer started, otherwise 0.
Definition at line 181 of file timer.cpp.
Stops periodic timer events.
- Returns:
- 1 if a timer was stopped, 0 if nothing to stop.
Definition at line 239 of file timer.cpp.
void Timer::TriggerEvents |
( |
) |
|
When called this method generates timer event callbacks.
Definition at line 554 of file timer.cpp.
The documentation for this class was generated from the following files:
- C:/Active/libraries/cxutils/2.0/include/cxutils/timer.h
- C:/Active/libraries/cxutils/2.0/src/cxutils/timer.cpp