nmsg 1.1.2
Functions
rate.h File Reference

Rate-limiting. More...

Go to the source code of this file.

Functions

nmsg_rate_t nmsg_rate_init (unsigned rate, unsigned freq)
 Initialize a new nmsg_rate_t object.
 
void nmsg_rate_destroy (nmsg_rate_t *r)
 Destroy an nmsg_rate_t object.
 
void nmsg_rate_sleep (nmsg_rate_t r)
 Sleep if necessary to maintain the target rate limit.
 

Detailed Description

Rate-limiting.

Tight loops can be slowed down by repeated calls to nmsg_rate_sleep(). This works best when the amount of time elapsed between successive calls is approximately the same.

Reliability:

Definition in file rate.h.

Function Documentation

◆ nmsg_rate_init()

nmsg_rate_t nmsg_rate_init ( unsigned  rate,
unsigned  freq 
)

Initialize a new nmsg_rate_t object.

'freq' should usually be about 1-10% of 'rate'.

Parameters
[in]ratetarget rate limit in Hz, greater than 0.
[in]freqhow often the rate limit will be checked, i.e., every 'freq' calls to nmsg_rate_sleep(), greater than 0.

◆ nmsg_rate_destroy()

void nmsg_rate_destroy ( nmsg_rate_t *  r)

Destroy an nmsg_rate_t object.

Parameters
[in]rpointer to an nmsg_rate_t object.

◆ nmsg_rate_sleep()

void nmsg_rate_sleep ( nmsg_rate_t  r)

Sleep if necessary to maintain the target rate limit.

Parameters
[in]rnmsg_rate_t object.