From: Otto Date: Mon, 2 Aug 2021 12:15:53 +0000 (+0200) Subject: Use explicit PacketIDCompare X-Git-Tag: dnsdist-1.7.0-alpha1~74^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0662c2d3c60bca6d99b0edd269630b23e913bdde;p=thirdparty%2Fpdns.git Use explicit PacketIDCompare --- diff --git a/pdns/mtasker.cc b/pdns/mtasker.cc index 8776a4e33f..c02e27781f 100644 --- a/pdns/mtasker.cc +++ b/pdns/mtasker.cc @@ -170,7 +170,7 @@ int main() \return returns -1 in case of error, 0 in case of timeout, 1 in case of an answer */ -templateint MTasker::waitEvent(EventKey &key, EventVal *val, unsigned int timeoutMsec, const struct timeval* now) +templateint MTasker::waitEvent(EventKey &key, EventVal *val, unsigned int timeoutMsec, const struct timeval* now) { if(d_waiters.count(key)) { // there was already an exact same waiter return -1; @@ -219,7 +219,7 @@ templateint MTasker::waitEven //! yields control to the kernel or other threads /** Hands over control to the kernel, allowing other processes to run, or events to arrive */ -templatevoid MTasker::yield() +templatevoid MTasker::yield() { d_runQueue.push(d_tid); notifyStackSwitchToKernel(); @@ -235,7 +235,7 @@ templatevoid MTasker::yield() WARNING: when passing val as zero, d_waitval is undefined, and hence waitEvent will return undefined! */ -templateint MTasker::sendEvent(const EventKey& key, const EventVal* val) +templateint MTasker::sendEvent(const EventKey& key, const EventVal* val) { typename waiters_t::iterator waiter=d_waiters.find(key); @@ -262,7 +262,7 @@ templateint MTasker::sendEven \param start Pointer to the function which will form the start of the thread \param val A void pointer that can be used to pass data to the thread */ -templatevoid MTasker::makeThread(tfunc_t *start, void* val) +templatevoid MTasker::makeThread(tfunc_t *start, void* val) { auto uc=std::make_shared(); @@ -303,7 +303,7 @@ templatevoid MTasker::makeThread(tfunc_t *start, \return Returns if there is more work scheduled and recalling schedule now would be useful */ -templatebool MTasker::schedule(const struct timeval* now) +templatebool MTasker::schedule(const struct timeval* now) { if(!d_runQueue.empty()) { d_tid=d_runQueue.front(); @@ -359,7 +359,7 @@ templatebool MTasker::schedule(const struct timev /** Call this to check if no processes are running anymore \return true if no processes are left */ -templatebool MTasker::noProcesses() const +templatebool MTasker::noProcesses() const { return d_threadsCount == 0; } @@ -368,7 +368,7 @@ templatebool MTasker::noProcesses() const /** Call this to perhaps limit activities if too many threads are running \return number of processes running */ -templateunsigned int MTasker::numProcesses() const +templateunsigned int MTasker::numProcesses() const { return d_threadsCount; } @@ -380,7 +380,7 @@ templateunsigned int MTasker::numProcesses() cons \param events Vector which is to be filled with keys threads are waiting for */ -templatevoid MTasker::getEvents(std::vector& events) +templatevoid MTasker::getEvents(std::vector& events) { events.clear(); for(typename waiters_t::const_iterator i=d_waiters.begin();i!=d_waiters.end();++i) { @@ -392,19 +392,19 @@ templatevoid MTasker::getEvents(std::vector& /** Processes can call this to get a numerical representation of their current thread ID. This can be useful for logging purposes. */ -templateint MTasker::getTid() const +templateint MTasker::getTid() const { return d_tid; } //! Returns the maximum stack usage so far of this MThread -templateuint64_t MTasker::getMaxStackUsage() +templateuint64_t MTasker::getMaxStackUsage() { return d_threads[d_tid].startOfStack - d_threads[d_tid].highestStackSeen; } //! Returns the maximum stack usage so far of this MThread -templateunsigned int MTasker::getUsec() +templateunsigned int MTasker::getUsec() { #ifdef MTASKERTIMING return d_threads[d_tid].totTime + d_threads[d_tid].dt.ndiff()/1000; diff --git a/pdns/mtasker.hh b/pdns/mtasker.hh index fa1ede4127..62bf590987 100644 --- a/pdns/mtasker.hh +++ b/pdns/mtasker.hh @@ -46,7 +46,7 @@ struct KeyTag {}; \note The EventKey needs to have an operator< defined because it is used as the key of an associative array */ -template class MTasker +template> class MTasker { private: pdns_ucontext_t d_kernel; @@ -87,10 +87,10 @@ public: typedef multi_index_container< Waiter, indexed_by < - ordered_unique >, - ordered_non_unique, member > - > - > waiters_t; + ordered_unique, Cmp>, + ordered_non_unique, member > + > + > waiters_t; waiters_t d_waiters; diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 64d5ede01b..172421a34a 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -5456,7 +5456,7 @@ try t_bogusqueryring = std::unique_ptr > >(new boost::circular_buffer >()); t_bogusqueryring->set_capacity(ringsize); } - MT=std::unique_ptr,PacketBuffer> >(new MTasker,PacketBuffer>(::arg().asNum("stack-size"))); + MT = std::make_unique(::arg().asNum("stack-size")); threadInfo.mt = MT.get(); /* start protobuf export threads if needed */ diff --git a/pdns/syncres.hh b/pdns/syncres.hh index ae5a7e5dd5..acca4f9951 100644 --- a/pdns/syncres.hh +++ b/pdns/syncres.hh @@ -967,21 +967,15 @@ struct PacketID bool operator<(const PacketID& b) const { - if (tie(remote, tcpsock, type) < tie(b.remote, b.tcpsock, b.type)) { - return true; - } - if (tie(remote, tcpsock, type) > tie(b.remote, b.tcpsock, b.type)) { - return false; - } - - return tie(domain, fd, id) < tie(b.domain, b.fd, b.id); + // We don't want explcit PacketID compare here, but always via predicate classes below + assert(0); } }; inline ostream& operator<<(ostream & os, const PacketID& pid) { return os << "PacketID(id=" << pid.id << ",remote=" << pid.remote.toString() << ",type=" << pid.type << ",tcpsock=" << - pid.tcpsock << "fd=" << pid.fd << ',' << pid.domain << ')'; + pid.tcpsock << ",fd=" << pid.fd << ',' << pid.domain << ')'; } inline ostream& operator<<(ostream & os, const shared_ptr& pid) @@ -989,10 +983,20 @@ inline ostream& operator<<(ostream & os, const shared_ptr& pid) return os << *pid; } -inline bool operator<(const std::shared_ptr& a, const std::shared_ptr& b) +struct PacketIDCompare { - return a->operator<(*b); -} + bool operator()(const std::shared_ptr& a, const std::shared_ptr& b) const + { + if (tie(a->remote, a->tcpsock, a->type) < tie(b->remote, b->tcpsock, b->type)) { + return true; + } + if (tie(a->remote, a->tcpsock, a->type) > tie(b->remote, b->tcpsock, b->type)) { + return false; + } + + return tie(a->domain, a->fd, a->id) < tie(b->domain, b->fd, b->id); + } +}; struct PacketIDBirthdayCompare { @@ -1009,7 +1013,7 @@ struct PacketIDBirthdayCompare }; extern std::unique_ptr g_recCache; extern thread_local std::unique_ptr t_packetCache; -typedef MTasker,PacketBuffer> MT_t; +typedef MTasker, PacketBuffer, PacketIDCompare> MT_t; MT_t* getMT(); struct RecursorStats