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 *distributor = new DNSDistributor(::arg().asNum("distributor-threads")); // the big dispatcher!
DNSPacket question;
DNSPacket cached;
if(!((numreceived++)%250)) { // maintenance tasks
S.set("latency",(int)avg_latency);
int qcount, acount;
- g_distributor->getQueueSizes(qcount, acount);
+ distributor->getQueueSizes(qcount, acount);
S.set("qsize-q",qcount);
}
}
continue;
}
- if(g_distributor->isOverloaded()) {
+ if(distributor->isOverloaded()) {
if(logDNSQueries)
L<<"Dropped query, db is overloaded"<<endl;
continue;
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
+ distributor->question(P, &sendout); // otherwise, give to the distributor
}
return 0;
}
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(unsigned int n=0; n < max_rthreads; ++n)
pthread_create(&qtid,0,qthread, reinterpret_cast<void *>(n)); // receives packets
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
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);