contention killer

pull/916/head
Jeff Becker 5 years ago
parent 99d76280be
commit d7f09a365d
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -10,7 +10,7 @@ namespace libuv
/// call a function in logic thread via a handle
template < typename Handle, typename Func >
void
Call(Handle* h, Func&& f)
Call(Handle* h, Func f)
{
static_cast< Loop* >(h->loop->data)->Call(f);
}
@ -416,7 +416,7 @@ namespace libuv
OnTick(uv_check_t* t)
{
ticker_glue* ticker = static_cast< ticker_glue* >(t->data);
Call(&ticker->m_Ticker, [ticker]() { ticker->func(); });
Call(t, ticker->func);
}
bool

@ -71,9 +71,12 @@ namespace llarp
void
OutboundMessageHandler::Tick()
{
ProcessOutboundQueue();
RemoveEmptyPathQueues();
SendRoundRobin();
auto self = this;
m_Killer.TryAccess([self]() {
self->ProcessOutboundQueue();
self->RemoveEmptyPathQueues();
self->SendRoundRobin();
});
}
void
@ -265,7 +268,9 @@ namespace llarp
void
OutboundMessageHandler::RemoveEmptyPathQueues()
{
removedSomePaths = (not removedPaths.empty());
removedSomePaths = false;
if(removedPaths.empty())
return;
while(not removedPaths.empty())
{
@ -275,6 +280,7 @@ namespace llarp
outboundMessageQueues.erase(itr);
}
}
removedSomePaths = true;
}
void
@ -282,7 +288,7 @@ namespace llarp
{
// send non-routing messages first priority
auto &non_routing_mq = outboundMessageQueues[zeroID];
while(!non_routing_mq.empty())
while(not non_routing_mq.empty())
{
MessageQueueEntry entry = std::move(non_routing_mq.front());
non_routing_mq.pop();

@ -123,6 +123,8 @@ namespace llarp
ILinkManager *_linkManager;
std::shared_ptr< Logic > _logic;
util::ContentionKiller m_Killer;
// paths cannot have pathid "0", so it can be used as the "pathid"
// for non-traffic (control) messages, so they can be prioritized.
static const PathID_t zeroID;

@ -53,5 +53,13 @@ namespace llarp
(void)name;
#endif
}
void
ContentionKiller::TryAccess(std::function< void(void) > visit) const
{
NullLock lock(&__access);
visit();
}
} // namespace util
} // namespace llarp

@ -156,6 +156,16 @@ namespace llarp
return ::getpid();
#endif
}
// type for detecting contention on a resource
struct ContentionKiller
{
void
TryAccess(std::function< void(void) > visit) const;
private:
mutable NullMutex __access;
};
} // namespace util
} // namespace llarp

Loading…
Cancel
Save