16 #include <unordered_map>
37 std::function<void()>
function;
48 explicit Timeout(
int max_tmos = 100);
60 void add_periodic(
const char* desc,
void* tag, std::function<
void()>&
function, uint64_t period_us, uint64_t start_us = 0);
71 void add_periodic(
const char* desc,
void* tag, std::function<
void()>&
function,
int rel_ms);
81 void add_periodic(
const char* desc, uint64_t period_us, uint64_t start_us = 0);
92 void add_relative(
const char* desc,
void* tag, std::function<
void()>&
function,
int rel_ms);
109 void copy_in_timeout(
const char* desc, uint64_t period_us, uint64_t start_us = 0);
154 std::mutex lock_mutex_;
155 std::vector<timeoutspec> tmospecs_;
156 std::list<size_t> free_;
157 std::multimap<uint64_t, size_t> active_time_;
158 std::unordered_multimap<std::string, size_t> active_desc_;
160 void timeoutlist_init();
162 int tmo_is_before_ts(
timeoutspec& tmo,
const timespec& ts);
164 int get_clear_next_expired_timeout(
timeoutspec& tmo, uint64_t tod_now_us);
void copy_in_timeout(const char *desc, uint64_t period_us, uint64_t start_us=0)
Add a timeout with the given parameters.
void add_relative(const char *desc, void *tag, std::function< void()> &function, int rel_ms)
Add a periodic timeout to the Timeout container.
void * tag
could be file descriptor (fd)
uint64_t tmo_tod_us
When the function should be executed (gettimeofday, microseconds)
The Timeout class performs registered actions at specified intervals.
int get_next_timeout_msdly()
Get the amount to wait for the next timeout to occur.
int check
Check the timeoutspec.
int missed_periods
Number of periods that passed while the function was executing.
void get_next_timeout_delay(int64_t *delay_us)
Get the amount to wait for the next timeout to occur.
uint64_t period_us
0 if not periodic
bool cancel_timeout(void *tag, const std::string &desc)
Cancel the timeout having the given description and tag.
Specification for a Timeout function.
int get_next_expired_timeout(std::string &desc, void **tag, std::function< void()> &function, uint64_t *tmo_tod_us)
Get a timeout that has expired.
bool is_consistent()
Run a consistency check on all confiugured timeouts.
std::string desc
Description of the Timeout function.
void add_periodic(const char *desc, void *tag, std::function< void()> &function, uint64_t period_us, uint64_t start_us=0)
Add a periodic timeout to the Timeout container.
Timeout(int max_tmos=100)
Construct a Timeout object.
void list_active_time()
TRACE all active timeouts.