Allolib  1.0
C++ Components For Interactive Multimedia
al::PeriodicThread Class Reference

Thread that calls a function periodically. More...

#include <C:/Users/Andres/source/repos/casm_viewer/external/tinc/external/allolib/include/al/system/al_PeriodicThread.hpp>

Inheritance diagram for al::PeriodicThread:
al::Thread

Public Member Functions

 PeriodicThread (double periodSec=1)
 
 PeriodicThread (const PeriodicThread &other)
 Copy constructor.
 
PeriodicThreadautocorrect (float factor)
 Set autocorrection factor. More...
 
PeriodicThreadperiod (double sec)
 Set period, in seconds.
 
double period () const
 Get period, in seconds.
 
void start (ThreadFunction &func)
 Start calling the supplied function periodically.
 
void start (std::function< void(void *data)> function, void *userData=nullptr)
 Start calling the supplied function periodically.
 
void stop ()
 Stop the thread.
 
bool running () const
 True if timer thread is running.
 
PeriodicThreadoperator= (PeriodicThread other)
 
ThreadjoinOnDestroy (bool v)
 Set whether thread will automatically join upon destruction.
 
Threadpriority (int v)
 Set thread priority. More...
 
bool start (void *(*threadFunc)(void *userData), void *userData)
 Start executing thread C function with user data.
 
bool join ()
 Block the calling routine indefinitely until the thread terminates. More...
 

Static Public Member Functions

static void * current ()
 Return pointer to current OS thread object. More...
 

Protected Attributes

Impl * mImpl
 
CThreadFunction mCFunc
 
bool mJoinOnDestroy
 

Friends

void swap (PeriodicThread &a, PeriodicThread &b)
 

Detailed Description

Thread that calls a function periodically.

The sleep time is dynamically adjusted based on the time taken by the user-supplied thread function. This prevents drift that would occur in a more simplistic implementation using a fixed sleep interval.

Definition at line 61 of file al_PeriodicThread.hpp.

Constructor & Destructor Documentation

◆ PeriodicThread()

al::PeriodicThread::PeriodicThread ( double  periodSec = 1)
Parameters
[in]periodSeccalling period in seconds
[in]oneShotdetermines if the timer triggers only once.
[in]triggerOnStartif true, calling start() calls the function, otherwise function is called on next timeout

Member Function Documentation

◆ autocorrect()

PeriodicThread& al::PeriodicThread::autocorrect ( float  factor)

Set autocorrection factor.

This parameter is used to compensate for occasional iterations that take longer than the expected iteration period. Smaller values mean the timing corrections will be spread over a larger number of iterations. If all iterations take longer than the period, then no autocorrection measures will be able to make up for the lost time.

Parameters
[in]factorMaximum fraction of one period, in [0,1], to try to make up each iteration if behind on timing.

◆ current()

static void* al::Thread::current ( )
staticinherited

Return pointer to current OS thread object.

E.g., if using pthreads internally, will return the pthread_t.

◆ join()

bool al::Thread::join ( )
inherited

Block the calling routine indefinitely until the thread terminates.

This function suspends execution of the calling routine until the thread has terminated. It will return immediately if the thread was already terminated. A true return value signifies successful termination. A false return value indicates a problem with the wait call.

◆ priority()

Thread& al::Thread::priority ( int  v)
inherited

Set thread priority.

Parameters
[in]vpriority of thread in [0, 99]. A value greater than 0 makes the thread "real-time".

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