1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00
lokinet/include/llarp/timer.h

49 lines
1,006 B
C
Raw Normal View History

2018-04-30 20:18:18 +02:00
#ifndef LLARP_TIMER_H
#define LLARP_TIMER_H
#include <llarp/common.h>
#include <llarp/threadpool.h>
#ifdef __cplusplus
extern "C" {
#endif
2018-05-16 17:30:05 +02:00
/** called with userptr, original timeout, left */
2018-04-30 20:18:34 +02:00
typedef void (*llarp_timer_handler_func)(void *, uint64_t, uint64_t);
2018-04-30 20:18:18 +02:00
struct llarp_timeout_job
{
2018-04-30 20:18:34 +02:00
uint64_t timeout;
void *user;
llarp_timer_handler_func handler;
};
2018-04-30 20:18:18 +02:00
2018-04-30 20:18:34 +02:00
struct llarp_timer_context;
2018-04-30 20:18:18 +02:00
struct llarp_timer_context *
llarp_init_timer();
2018-04-30 20:18:18 +02:00
uint32_t
llarp_timer_call_later(struct llarp_timer_context *t,
struct llarp_timeout_job job);
2018-04-30 20:18:34 +02:00
void
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 20:18:34 +02:00
// cancel all
void
llarp_timer_stop(struct llarp_timer_context *t);
2018-04-30 20:18:34 +02:00
// blocking run timer and send events to thread pool
void
llarp_timer_run(struct llarp_timer_context *t, struct llarp_threadpool *pool);
2018-04-30 20:18:34 +02:00
void
llarp_free_timer(struct llarp_timer_context **t);
2018-04-30 20:18:18 +02:00
#ifdef __cplusplus
}
#endif
#endif