lokinet/llarp/util/thread/logic.hpp

56 lines
953 B
C++
Raw Normal View History

2018-11-19 23:57:28 +00:00
#ifndef LLARP_LOGIC_HPP
#define LLARP_LOGIC_HPP
#include <util/mem.h>
2019-09-01 13:26:16 +00:00
#include <util/thread/threadpool.h>
#include <util/thread/timer.hpp>
2019-10-02 13:17:12 +00:00
#include <absl/types/optional.h>
2018-04-30 18:18:18 +00:00
2018-12-10 14:14:55 +00:00
namespace llarp
2018-07-09 04:26:27 +00:00
{
2018-12-10 14:14:55 +00:00
class Logic
{
public:
Logic();
2018-06-06 12:46:26 +00:00
2019-09-05 21:28:50 +00:00
~Logic();
/// trigger times as needed
2018-12-10 14:14:55 +00:00
void
tick(llarp_time_t now);
2018-06-06 12:46:26 +00:00
/// stop all operation and wait for that to die
2018-12-10 14:14:55 +00:00
void
stop();
2018-04-30 18:18:18 +00:00
bool
2018-12-10 14:14:55 +00:00
queue_job(struct llarp_thread_job job);
2018-04-30 18:18:18 +00:00
2019-05-15 15:54:26 +00:00
bool
queue_func(std::function< void(void) > func);
2018-12-10 14:14:55 +00:00
uint32_t
2019-01-03 21:54:26 +00:00
call_later(const llarp_timeout_job& job);
void
call_later(llarp_time_t later, std::function< void(void) > func);
2018-12-10 14:14:55 +00:00
void
cancel_call(uint32_t id);
2018-12-10 14:14:55 +00:00
void
remove_call(uint32_t id);
bool
can_flush() const;
private:
using ID_t = std::thread::id;
llarp_threadpool* const m_Thread;
llarp_timer_context* const m_Timer;
absl::optional< ID_t > m_ID;
2018-12-10 14:14:55 +00:00
};
} // namespace llarp
2018-04-30 18:18:18 +00:00
#endif