From: Remi Gacogne Date: Fri, 29 Mar 2019 12:32:46 +0000 (+0100) Subject: rec: Keep track of the number of MTasks in a dedicated variable X-Git-Tag: dnsdist-1.4.0-alpha1~38^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c4975eaf7bceb7cd0647131622a2273b1e891b44;p=pdns rec: Keep track of the number of MTasks in a dedicated variable (cherry picked from commit 03a5d29ea3456fd3798ca71ed4f0f7ec7980ee2c) --- diff --git a/pdns/mtasker.cc b/pdns/mtasker.cc index 16027b610..2d01f12f2 100644 --- a/pdns/mtasker.cc +++ b/pdns/mtasker.cc @@ -274,6 +274,7 @@ templatevoid MTasker::makeThread(tfunc_t *start, &uc->uc_stack[uc->uc_stack.size()-1]); #endif /* PDNS_USE_VALGRIND */ + ++d_threadsCount; auto& thread = d_threads[d_maxtid]; auto mt = this; thread.start = [start, val, mt]() { @@ -316,6 +317,7 @@ templatebool MTasker::schedule(struct timeval* n } if(!d_zombiesQueue.empty()) { d_threads.erase(d_zombiesQueue.front()); + --d_threadsCount; d_zombiesQueue.pop(); return true; } @@ -357,7 +359,7 @@ templatebool MTasker::schedule(struct timeval* n */ templatebool MTasker::noProcesses() const { - return d_threads.empty(); + return d_threadsCount == 0; } //! returns the number of processes running @@ -366,7 +368,7 @@ templatebool MTasker::noProcesses() const */ templateunsigned int MTasker::numProcesses() const { - return d_threads.size(); + return d_threadsCount; } //! gives access to the list of Events threads are waiting for diff --git a/pdns/mtasker.hh b/pdns/mtasker.hh index 87bc6723c..0365e756a 100644 --- a/pdns/mtasker.hh +++ b/pdns/mtasker.hh @@ -68,9 +68,10 @@ private: typedef std::map mthreads_t; mthreads_t d_threads; + size_t d_stacksize; + size_t d_threadsCount; int d_tid; int d_maxtid; - size_t d_stacksize; EventVal d_waitval; enum waitstatusenum {Error=-1,TimeOut=0,Answer} d_waitstatus; @@ -110,7 +111,7 @@ public: This limit applies solely to the stack, the heap is not limited in any way. If threads need to allocate a lot of data, the use of new/delete is suggested. */ - MTasker(size_t stacksize=16*8192) : d_tid(0), d_maxtid(0), d_stacksize(stacksize), d_waitstatus(Error) + MTasker(size_t stacksize=16*8192) : d_stacksize(stacksize), d_threadsCount(0), d_tid(0), d_maxtid(0), d_waitstatus(Error) { initMainStackBounds();