lokinet/llarp/util/thread/logic.cpp

72 lines
1.1 KiB
C++
Raw Normal View History

2019-09-01 13:26:16 +00:00
#include <util/thread/logic.hpp>
2019-09-01 12:10:49 +00:00
#include <util/logging/logger.hpp>
#include <util/mem.h>
2018-04-30 18:18:18 +00:00
#include <future>
2018-12-10 14:14:55 +00:00
namespace llarp
{
2018-12-10 14:14:55 +00:00
void
Logic::stop()
{
llarp::LogDebug("logic thread stop");
}
2018-05-18 20:08:57 +00:00
void
Logic::Call(std::function<void(void)> func)
{
m_Queue(std::move(func));
}
void
Logic::SetQueuer(std::function<void(std::function<void(void)>)> q)
{
m_Queue = std::move(q);
}
uint32_t
Logic::call_later(llarp_time_t timeout, std::function<void(void)> func)
{
auto loop = m_Loop;
if (loop != nullptr)
{
return loop->call_after_delay(timeout, func);
}
return 0;
}
2018-12-10 14:14:55 +00:00
void
Logic::cancel_call(uint32_t id)
{
auto loop = m_Loop;
if (loop != nullptr)
{
loop->cancel_delayed_call(id);
}
2018-12-10 14:14:55 +00:00
}
2018-12-10 14:14:55 +00:00
void
Logic::remove_call(uint32_t id)
{
auto loop = m_Loop;
if (loop != nullptr)
{
loop->cancel_delayed_call(id);
}
2018-12-10 14:14:55 +00:00
}
void
Logic::set_event_loop(EventLoop* loop)
{
m_Loop = loop;
SetQueuer([loop](std::function<void(void)> work) { loop->call_soon(work); });
}
void
Logic::clear_event_loop()
{
m_Loop = nullptr;
}
2018-12-10 14:14:55 +00:00
} // namespace llarp