mirror of
https://github.com/znc/znc.git
synced 2026-08-07 09:22:55 +02:00
Threaded DNS: Use a thread pool
When a DNS thread is done with its lookup, instead of existing immediately, it now waits for another DNS lookup to do instead. This avoids the cost of starting/stopping threads all the time. To make sure that (for whatever reason) the number of waiting threads doesn't get too high, threads exit if there are more than two DNS threads idling around with nothing to do. Fixes #132. Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
@@ -129,10 +129,27 @@ private:
|
||||
int iRes;
|
||||
addrinfo* aiResult;
|
||||
};
|
||||
struct TDNSStatus {
|
||||
/* mutex which protects this whole struct */
|
||||
pthread_mutex_t mutex;
|
||||
/* condition variable for idle threads */
|
||||
pthread_cond_t cond;
|
||||
/* When this is true, all threads should exit */
|
||||
bool done;
|
||||
/* Total number of running DNS threads */
|
||||
size_t num_threads;
|
||||
/* Number of DNS threads which don't have any work */
|
||||
size_t num_idle;
|
||||
/* List of pending DNS jobs */
|
||||
std::list<TDNSArg *> jobs;
|
||||
};
|
||||
void StartTDNSThread(TDNSTask* task, bool bBind);
|
||||
void SetTDNSThreadFinished(TDNSTask* task, bool bBind, addrinfo* aiResult);
|
||||
void RetrieveTDNSResult();
|
||||
static void* TDNSThread(void* argument);
|
||||
static void DoDNS(TDNSArg *arg);
|
||||
|
||||
TDNSStatus m_threadStatus;
|
||||
#endif
|
||||
protected:
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user