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

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

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

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

@ -156,6 +156,16 @@ namespace llarp
return ::getpid(); return ::getpid();
#endif #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 util
} // namespace llarp } // namespace llarp

Loading…
Cancel
Save