2019-01-11 01:19:36 +00:00
|
|
|
#include <util/logic.hpp>
|
2019-01-10 19:41:51 +00:00
|
|
|
|
|
|
|
#include <util/logger.hpp>
|
|
|
|
#include <util/mem.h>
|
2018-04-30 18:18:18 +00:00
|
|
|
|
2018-12-10 14:14:55 +00:00
|
|
|
namespace llarp
|
2018-05-22 15:54:19 +00:00
|
|
|
{
|
2018-12-10 14:14:55 +00:00
|
|
|
void
|
|
|
|
Logic::tick(llarp_time_t now)
|
2018-05-22 15:54:19 +00:00
|
|
|
{
|
2018-12-10 14:14:55 +00:00
|
|
|
llarp_timer_set_time(this->timer, now);
|
|
|
|
llarp_timer_tick_all(this->timer);
|
|
|
|
llarp_threadpool_tick(this->thread);
|
2018-04-30 18:18:18 +00:00
|
|
|
}
|
|
|
|
|
2018-12-10 14:14:55 +00:00
|
|
|
void
|
|
|
|
Logic::tick_async(llarp_time_t now)
|
2018-06-06 12:46:26 +00:00
|
|
|
{
|
2018-12-10 14:14:55 +00:00
|
|
|
llarp_timer_tick_all_async(this->timer, this->thread, now);
|
|
|
|
llarp_threadpool_tick(this->thread);
|
2018-06-06 12:46:26 +00:00
|
|
|
}
|
|
|
|
|
2018-12-10 14:14:55 +00:00
|
|
|
void
|
|
|
|
Logic::stop_timer()
|
2018-05-22 15:54:19 +00:00
|
|
|
{
|
2018-12-10 14:14:55 +00:00
|
|
|
llarp_timer_stop(this->timer);
|
2018-04-30 18:18:18 +00:00
|
|
|
}
|
|
|
|
|
2018-12-10 14:14:55 +00:00
|
|
|
void
|
|
|
|
Logic::queue_job(struct llarp_thread_job job)
|
2018-05-28 20:51:15 +00:00
|
|
|
{
|
2018-12-10 14:14:55 +00:00
|
|
|
if(job.user && job.work)
|
|
|
|
llarp_threadpool_queue_job(this->thread, {job.user, job.work});
|
2018-05-28 20:51:15 +00:00
|
|
|
}
|
|
|
|
|
2018-12-10 14:14:55 +00:00
|
|
|
void
|
|
|
|
Logic::stop()
|
|
|
|
{
|
|
|
|
llarp::LogDebug("logic thread stop");
|
|
|
|
if(this->thread)
|
|
|
|
{
|
|
|
|
llarp_threadpool_stop(this->thread);
|
|
|
|
llarp_threadpool_join(this->thread);
|
|
|
|
}
|
|
|
|
llarp_free_threadpool(&this->thread);
|
2018-04-30 18:18:18 +00:00
|
|
|
|
2018-12-10 14:14:55 +00:00
|
|
|
llarp::LogDebug("logic timer stop");
|
|
|
|
if(this->timer)
|
|
|
|
llarp_timer_stop(this->timer);
|
|
|
|
}
|
2018-05-17 20:00:58 +00:00
|
|
|
|
2018-12-10 14:14:55 +00:00
|
|
|
void
|
|
|
|
Logic::mainloop()
|
|
|
|
{
|
|
|
|
llarp_timer_run(this->timer, this->thread);
|
|
|
|
}
|
2018-05-18 20:08:57 +00:00
|
|
|
|
2018-12-10 14:14:55 +00:00
|
|
|
uint32_t
|
2019-01-03 21:54:26 +00:00
|
|
|
Logic::call_later(const llarp_timeout_job& job)
|
2018-12-10 14:14:55 +00:00
|
|
|
{
|
|
|
|
llarp_timeout_job j;
|
|
|
|
j.user = job.user;
|
|
|
|
j.timeout = job.timeout;
|
|
|
|
j.handler = job.handler;
|
|
|
|
return llarp_timer_call_later(this->timer, j);
|
|
|
|
}
|
2018-05-17 20:00:58 +00:00
|
|
|
|
2018-12-10 14:14:55 +00:00
|
|
|
void
|
|
|
|
Logic::cancel_call(uint32_t id)
|
|
|
|
{
|
|
|
|
llarp_timer_cancel_job(this->timer, id);
|
|
|
|
}
|
2018-05-27 12:49:10 +00:00
|
|
|
|
2018-12-10 14:14:55 +00:00
|
|
|
void
|
|
|
|
Logic::remove_call(uint32_t id)
|
|
|
|
{
|
|
|
|
llarp_timer_remove_job(this->timer, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace llarp
|