2018-04-30 18:18:18 +00:00
|
|
|
#ifndef LLARP_TIMER_H
|
|
|
|
#define LLARP_TIMER_H
|
|
|
|
#include <llarp/common.h>
|
|
|
|
#include <llarp/threadpool.h>
|
2018-10-29 16:48:36 +00:00
|
|
|
#include <llarp/time.h>
|
2018-04-30 18:18:18 +00:00
|
|
|
|
2018-05-16 15:30:05 +00:00
|
|
|
/** called with userptr, original timeout, left */
|
2018-04-30 18:18:34 +00:00
|
|
|
typedef void (*llarp_timer_handler_func)(void *, uint64_t, uint64_t);
|
2018-04-30 18:18:18 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
struct llarp_timeout_job
|
|
|
|
{
|
2018-04-30 18:18:34 +00:00
|
|
|
uint64_t timeout;
|
|
|
|
void *user;
|
|
|
|
llarp_timer_handler_func handler;
|
|
|
|
};
|
2018-04-30 18:18:18 +00:00
|
|
|
|
2018-04-30 18:18:34 +00:00
|
|
|
struct llarp_timer_context;
|
2018-04-30 18:18:18 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
struct llarp_timer_context *
|
|
|
|
llarp_init_timer();
|
2018-04-30 18:18:18 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
uint32_t
|
|
|
|
llarp_timer_call_later(struct llarp_timer_context *t,
|
|
|
|
struct llarp_timeout_job job);
|
2018-04-30 18:18:34 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
void
|
2018-05-27 12:49:10 +00:00
|
|
|
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);
|
2018-04-30 18:18:34 +00:00
|
|
|
|
|
|
|
// cancel all
|
2018-05-22 15:54:19 +00:00
|
|
|
void
|
|
|
|
llarp_timer_stop(struct llarp_timer_context *t);
|
2018-04-30 18:18:34 +00:00
|
|
|
|
2018-10-29 16:48:36 +00:00
|
|
|
/// 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);
|
|
|
|
|
2018-04-30 18:18:34 +00:00
|
|
|
// blocking run timer and send events to thread pool
|
2018-05-22 15:54:19 +00:00
|
|
|
void
|
|
|
|
llarp_timer_run(struct llarp_timer_context *t, struct llarp_threadpool *pool);
|
2018-04-30 18:18:34 +00:00
|
|
|
|
2018-06-06 12:46:26 +00:00
|
|
|
/// single threaded run timer, tick all timers
|
|
|
|
void
|
2018-08-09 19:02:17 +00:00
|
|
|
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,
|
2018-10-29 16:48:36 +00:00
|
|
|
struct llarp_threadpool *pool, llarp_time_t now);
|
2018-06-06 12:46:26 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
void
|
|
|
|
llarp_free_timer(struct llarp_timer_context **t);
|
2018-04-30 18:18:18 +00:00
|
|
|
|
|
|
|
#endif
|