EventLoop: add public wakeup() method, and call it from call()

call(), when invoked from the logic thread, wasn't triggering a wakeup
which stalled some traffic (such as client-to-snode packets).

Fix it by triggering a wakeup on `call()`, and expose it because this is
a useful thing to be able to do.
pull/1557/head
Jason Rhinelander 3 years ago
parent f8d5e106a0
commit 895acc45ff

@ -77,6 +77,12 @@ namespace llarp
return llarp::time_now_ms();
}
// Triggers an event loop wakeup; use when something has been done that requires the event loop
// to wake up (e.g. adding to queues). This is called implicitly by call() and call_soon().
// Idempotent and thread-safe.
virtual void
wakeup() = 0;
// Calls a function/lambda/etc. If invoked from within the event loop itself this calls the
// given lambda immediately; otherwise it passes it to `call_soon()` to be queued to run at the
// next event loop iteration.
@ -85,7 +91,10 @@ namespace llarp
call(Callable&& f)
{
if (inEventLoop())
{
f();
wakeup();
}
else
call_soon(std::forward<Callable>(f));
}

@ -149,6 +149,12 @@ namespace llarp::uv
llarp::LogInfo("we have stopped");
}
void
Loop::wakeup()
{
m_WakeUp->send();
}
void
Loop::set_pump_function(std::function<void(void)> pump)
{

@ -32,6 +32,9 @@ namespace llarp::uv
bool
running() const override;
void
wakeup() override;
void
call_later(llarp_time_t delay_ms, std::function<void(void)> callback) override;

Loading…
Cancel
Save