Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion llarp/router/router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,23 @@ namespace llarp
_lastTick = llarp::time_now_ms();
m_NextExploreAt = Clock_t::now();
m_Pump = _loop->make_waker([this]() { PumpLL(); });
m_Work = _loop->make_waker([this]() { submit_work(); });
}

Router::~Router()
{
llarp_dht_context_free(_dht);
}

void
Router::submit_work()
{
m_lmq->job([work = std::move(m_WorkJobs)]() {
for (const auto& job : work)
job();
});
}

void
Router::PumpLL()
{
Expand Down Expand Up @@ -1631,7 +1641,10 @@ namespace llarp
void
Router::QueueWork(std::function<void(void)> func)
{
m_lmq->job(std::move(func));
_loop->call([this, func = std::move(func)]() mutable {
m_WorkJobs.push_back(std::move(func));
m_Work->Trigger();
});
}

void
Expand Down
8 changes: 8 additions & 0 deletions llarp/router/router.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ namespace llarp
path::BuildLimiter m_PathBuildLimiter;

std::shared_ptr<EventLoopWakeup> m_Pump;
std::shared_ptr<EventLoopWakeup> m_Work;
std::vector<std::function<void()>> m_WorkJobs;

/// submits cpu heavy work from last event loop tick cycle to worker threads.
void
submit_work();

path::BuildLimiter&
pathBuildLimiter() override
Expand Down Expand Up @@ -196,9 +202,11 @@ namespace llarp
return _vpnPlatform.get();
}

/// queue functionally pure cpu heavy work to be done in another thread.
void
QueueWork(std::function<void(void)> func) override;

/// queue disk io bound work to be done in the disk io thread.
void
QueueDiskIO(std::function<void(void)> func) override;

Expand Down