Skip to content

Instantly share code, notes, and snippets.

@Habbie
Created April 26, 2013 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Habbie/5466799 to your computer and use it in GitHub Desktop.
Save Habbie/5466799 to your computer and use it in GitHub Desktop.
Index: pdns/distributor.hh
===================================================================
--- pdns/distributor.hh (revision 2708)
+++ pdns/distributor.hh (working copy)
@@ -171,15 +171,16 @@
QuestionData QD=us->questions.front();
+ us->questions.pop();
+ pthread_mutex_unlock(&us->q_lock);
+
Question *q=QD.Q;
- us->questions.pop();
if(us->d_overloaded && qcount <= overloadQueueLength/10) {
us->d_overloaded=false;
}
- pthread_mutex_unlock(&us->q_lock);
Answer *a;
#ifndef SMTPREDIR
@@ -297,11 +298,12 @@
pthread_create(&tid,0,&makeThread,static_cast<void *>(this));
}
- pthread_mutex_lock(&q_lock);
QuestionData QD;
QD.Q=q;
QD.id=nextid++;
QD.callback=callback;
+
+ pthread_mutex_lock(&q_lock);
questions.push(QD);
pthread_mutex_unlock(&q_lock);
Index: pdns/common_startup.cc
===================================================================
--- pdns/common_startup.cc (revision 2708)
+++ pdns/common_startup.cc (working copy)
@@ -210,14 +210,21 @@
delete AD.A;
}
-static DNSDistributor* g_distributor;
-static pthread_mutex_t d_distributorlock =PTHREAD_MUTEX_INITIALIZER;
-static bool g_mustlockdistributor;
//! The qthread receives questions over the internet via the Nameserver class, and hands them to the Distributor for further processing
void *qthread(void *number)
{
DNSPacket *P;
+ DNSDistributor *g_distributor = new DNSDistributor(::arg().asNum("distributor-threads")); // the big dispatcher!
DNSPacket question;
DNSPacket cached;
@@ -298,12 +305,7 @@
if(logDNSQueries)
L<<"packetcache MISS"<<endl;
- if(g_mustlockdistributor) {
- Lock l(&d_distributorlock);
- g_distributor->question(P, &sendout); // otherwise, give to the distributor
- }
- else
- g_distributor->question(P, &sendout); // otherwise, give to the distributor
+ g_distributor->question(P, &sendout); // otherwise, give to the distributor
}
return 0;
}
@@ -359,10 +361,7 @@
TN->go(); // tcp nameserver launch
// fork(); (this worked :-))
- g_distributor = new DNSDistributor(::arg().asNum("distributor-threads")); // the big dispatcher!
- if(::arg().asNum("receiver-threads") > 1) {
- g_mustlockdistributor=true;
- }
+
unsigned int max_rthreads= ::arg().asNum("receiver-threads");
for(int n=0; n < max_rthreads; ++n)
pthread_create(&qtid,0,qthread, reinterpret_cast<void *>(n)); // receives packets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment