MLIB
Loading...
Searching...
No Matches
mlib::wtimer Class Reference

Waitable timer. More...

Inheritance diagram for mlib::wtimer:
mlib::syncbase

Public Types

enum  mode { manual , automatic }
 Timer mode.
 

Public Member Functions

 wtimer (mode m=automatic, const std::string &name=std::string(), bool use_apc=false)
 
void start (DWORD interval_ms, DWORD period_ms=0)
 Set the start time of the timer and it's period.
 
void at (FILETIME &utctime, DWORD period_ms=0)
 Set the timer at an absolute time.
 
void stop ()
 Stop the timer.
 
- Public Member Functions inherited from mlib::syncbase
 syncbase ()
 Default constructor.
 
 syncbase (const syncbase &e)
 Copy constructor.
 
 syncbase (syncbase &&e) noexcept
 Move constructor.
 
virtual ~syncbase ()
 Destructor.
 
syncbaseoperator= (const syncbase &rhs)
 Assignment operator.
 
syncbaseoperator= (syncbase &&rhs) noexcept
 Move assignment operator.
 
int operator== (const syncbase &rhs) const
 Equality operator.
 
virtual void wait ()
 Wait for object to become signaled.
 
virtual DWORD wait (DWORD limit_msec)
 Wait a number of milliseconds for the object to become signaled.
 
virtual DWORD wait (std::chrono::milliseconds limit)
 Wait a number of milliseconds for the object to become signaled.
 
virtual DWORD wait_alertable (DWORD limit_msec=INFINITE)
 
virtual DWORD wait_msg (DWORD limit_msec=INFINITE, DWORD mask=QS_ALLINPUT)
 Wait for object to become signaled or a message to be queued.
 
 operator bool ()
 Check if object is signaled.
 
virtual bool is_signaled ()
 Try to wait on the object.
 
HANDLE handle () const
 Return OS handle of this object.
 
virtual const std::string & name () const
 Return object's name.
 

Protected Member Functions

virtual void at_timer (DWORD loval, DWORD hival)
 Function called for timers that use the APC feature.
 
- Protected Member Functions inherited from mlib::syncbase
 syncbase (const std::string &name)
 Protected constructor.
 
void set_handle (HANDLE h)
 Change object's handle. Closes the previous one.
 
virtual void name (const std::string &nam)
 Change object's name.
 

Detailed Description

Waitable timer.

A waitable timer object is set to signaled when the specified due time arrives. There are two types of waitable timers that can be created: manual and automatic (called synchronization timers in Windows documentation). Automatic timers are reset to their non-signaled state when a thread completes a wait operation on the object (similar to automatic events).

Manual timers remain signaled until restarted.

A timer of either type can also be a periodic timer.

When signaled, waitable timers can call the at_timer function as an APC (Asynchronous Procedure Call) to be executed in the context of the thread that created the timer. To use this feature you need to derive another class that re-implements the at_timer function.

Constructor & Destructor Documentation

◆ wtimer()

mlib::wtimer::wtimer ( mode  m = automatic,
const std::string &  name = std::string (),
bool  use_apc = false 
)
Parameters
mtimer type (manual or automatic)
nameobject's name
use_apctrue if object's at_timer function should be called

Member Function Documentation

◆ at()

void mlib::wtimer::at ( FILETIME &  utctime,
DWORD  period = 0 
)

Set the timer at an absolute time.

Parameters
utctimeUTC time when object should become signaled
periodtimer's period (0 if it's a one-shot)

◆ start()

void mlib::wtimer::start ( DWORD  interval,
DWORD  period = 0 
)

Set the start time of the timer and it's period.

Parameters
intervaltime in milliseconds from now when object should be signaled
periodtimer's period (0 if it's a one-shot)

The documentation for this class was generated from the following files: