mirror of https://github.com/oxen-io/lokinet
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.5 KiB
C++
62 lines
1.5 KiB
C++
6 years ago
|
#ifndef LLARP_TIMER_HPP
|
||
|
#define LLARP_TIMER_HPP
|
||
|
|
||
6 years ago
|
#include <util/common.hpp>
|
||
|
#include <util/threadpool.h>
|
||
|
#include <util/time.hpp>
|
||
7 years ago
|
|
||
6 years ago
|
#include <functional>
|
||
|
|
||
6 years ago
|
/** called with userptr, original timeout, left */
|
||
6 years ago
|
using llarp_timer_handler_func =
|
||
|
std::function< void(void *, uint64_t, uint64_t) >;
|
||
7 years ago
|
|
||
6 years ago
|
struct llarp_timeout_job
|
||
|
{
|
||
7 years ago
|
uint64_t timeout;
|
||
|
void *user;
|
||
|
llarp_timer_handler_func handler;
|
||
|
};
|
||
7 years ago
|
|
||
7 years ago
|
struct llarp_timer_context;
|
||
7 years ago
|
|
||
6 years ago
|
struct llarp_timer_context *
|
||
|
llarp_init_timer();
|
||
7 years ago
|
|
||
6 years ago
|
uint32_t
|
||
|
llarp_timer_call_later(struct llarp_timer_context *t,
|
||
|
struct llarp_timeout_job job);
|
||
7 years ago
|
|
||
6 years ago
|
void
|
||
6 years ago
|
llarp_timer_cancel_job(struct llarp_timer_context *t, uint32_t id);
|
||
|
|
||
|
void
|
||
|
llarp_timer_remove_job(struct llarp_timer_context *t, uint32_t id);
|
||
7 years ago
|
|
||
|
// cancel all
|
||
6 years ago
|
void
|
||
|
llarp_timer_stop(struct llarp_timer_context *t);
|
||
7 years ago
|
|
||
6 years ago
|
/// set timer's timestamp, if now is 0 use the current time from system clock,
|
||
|
/// llarp_time_t now
|
||
|
void
|
||
|
llarp_timer_set_time(struct llarp_timer_context *t, llarp_time_t now);
|
||
|
|
||
7 years ago
|
// blocking run timer and send events to thread pool
|
||
6 years ago
|
void
|
||
|
llarp_timer_run(struct llarp_timer_context *t, struct llarp_threadpool *pool);
|
||
7 years ago
|
|
||
6 years ago
|
/// single threaded run timer, tick all timers
|
||
|
void
|
||
6 years ago
|
llarp_timer_tick_all(struct llarp_timer_context *t);
|
||
|
|
||
|
/// tick all timers into a threadpool asynchronously
|
||
|
void
|
||
|
llarp_timer_tick_all_async(struct llarp_timer_context *t,
|
||
6 years ago
|
struct llarp_threadpool *pool, llarp_time_t now);
|
||
6 years ago
|
|
||
6 years ago
|
void
|
||
|
llarp_free_timer(struct llarp_timer_context **t);
|
||
7 years ago
|
|
||
|
#endif
|