|
| Timer (size_t interval, const String &name, size_t priority, size_t cpuAffinity=0) |
| Constructs an Timer instance. More...
|
|
| ~Timer (void) |
| Destructs this instance and frees all resources.
|
|
bool | IsRunning (void) const |
| Checks if the timer is running, i.e. Start was already invoked. More...
|
|
void | SetInterval (size_t interval) |
| Changes the interval in which the assigned methods are called. More...
|
|
size_t | GetInterval (void) const |
| Returns the interval value in microseconds. More...
|
|
void | SetCpuAffinity (size_t affinity) |
| Pins the timer to a specific CPUs inside a multiprocessor system. More...
|
|
size_t | GetCpuAffinity (void) const |
| Returns the current used CPU affinity mask. More...
|
|
void | SetName (const String &value) |
| Sets a new name for the timer. More...
|
|
const String & | GetName (void) const |
| Returns the current name of the timer. More...
|
|
void | SetPriority (size_t value) |
| Sets a new scheduling priority for the timer. More...
|
|
size_t | GetPriority (void) const |
| Returns the current scheduling priority of the timer. More...
|
|
void | Start (void) |
| Starts the execution of the timer. More...
|
|
void | Stop (void) |
| Stops the execution of the timer.
|
|
High resolution timer for interval based executions.
Instances of this class can be used to execute class methods periodically in a defined time intervall. The timer class itself takes care of computing the next timepoint where method has to be invoked. The developer only has to implement the class method that should be invoked whenever a specific interval expires.
A simple example that implements a counter that is incremented every 100 us is implemented by the following code
struct TimerNotifyHandler
{
TimerNotifyHandler(void) : NotifyCount(0) {}
void OnTimerNotify(void) { ++this->NotifyCount; }
int NotifyCount;
};
TimerNotifyHandler handler;
Timer timer(100,
"counterTimer", 0);
timer.Notify +=
make_delegate(&handler, &TimerNotifyHandler::OnTimerNotify);
timer.Start()
Timer(size_t interval, const String &name, size_t priority, size_t cpuAffinity=0)
Constructs an Timer instance.
delegate< R(A...)> make_delegate(R(*const function_ptr)(A...)) noexcept
Creates a delegate from a static function.
Definition: delegate.hxx:225
It is also possible to ad more than one method to the notification list of the timer instance.
TimerNotifyHandler handler2;
timer.Notify +=
make_delegate(&handler2, &TimerNotifyHandler::OnTimerNotify);
The methods will be called in the order they are assigned to the timers notification list.