Move to different way of enforcing max_pending. Should require less locks.

remotes/origin/master-1.0.x
Victor Julien 16 years ago
parent 42c4b5d53c
commit ccf22cf563

@ -103,12 +103,6 @@ void PcapFileCallback(char *user, struct pcap_pkthdr *h, u_char *pkt) {
PcapFileThreadVars *ptv = (PcapFileThreadVars *)user;
SCMutexLock(&mutex_pending);
if (pending > max_pending_packets) {
SCondWait(&cond_pending, &mutex_pending);
}
SCMutexUnlock(&mutex_pending);
Packet *p = ptv->in_p;
p->ts.tv_sec = h->ts.tv_sec;

@ -219,12 +219,13 @@ Packet *SetupPktWait (void)
Packet *SetupPkt (void)
{
Packet *p = NULL;
int r = 0;
r = SCMutexLock(&packet_q.mutex_q);
p = PacketDequeue(&packet_q);
r = SCMutexUnlock(&packet_q.mutex_q);
SCMutexLock(&packet_q.mutex_q);
while ((p = PacketDequeue(&packet_q)) == NULL) {
SCondWait(&packet_q.cond_q, &packet_q.mutex_q);
}
SCMutexUnlock(&packet_q.mutex_q);
/*
if (p == NULL) {
TmqDebugList();
@ -240,7 +241,7 @@ Packet *SetupPkt (void)
SCLogDebug("allocated a new packet...");
}
*/
/* reset the packet csum fields */
RESET_PACKET_CSUMS(p);
@ -280,29 +281,6 @@ Packet *TunnelPktSetup(ThreadVars *t, DecodeThreadVars *dtv, Packet *parent, uin
/* get us a packet */
Packet *p = SetupPkt();
int r = 0;
#if 0
do {
r = SCMutexLock(&packet_q.mutex_q);
p = PacketDequeue(&packet_q);
SCMutexUnlock(&packet_q.mutex_q);
if (p == NULL) {
//TmqDebugList();
usleep(1000); /* sleep 1ms */
/* XXX check for recv'd signals, so
* we can exit on signals received */
}
} while (p == NULL);
#endif
r = SCMutexLock(&mutex_pending);
pending++;
#ifdef DBG_PERF
if (pending > dbg_maxpending)
dbg_maxpending = pending;
#endif /* DBG_PERF */
SCMutexUnlock(&mutex_pending);
/* set the root ptr to the lowest layer */
if (parent->root != NULL)
@ -1043,10 +1021,10 @@ int main(int argc, char **argv)
if (sigflags & SURICATA_SIGTERM || sigflags & SURICATA_KILL)
break;
SCMutexLock(&mutex_pending);
if (pending == 0)
SCMutexLock(&packet_q.mutex_q);
if (packet_q.len == max_pending_packets)
done = 1;
SCMutexUnlock(&mutex_pending);
SCMutexUnlock(&packet_q.mutex_q);
if (done == 0) {
usleep(100);

@ -147,6 +147,7 @@ void TmqhOutputPacketpool(ThreadVars *t, Packet *p)
SCMutexLock(&q->mutex_q);
PacketEnqueue(q, p->root);
SCCondSignal(&q->cond_q);
SCMutexUnlock(&q->mutex_q);
}
@ -154,25 +155,8 @@ void TmqhOutputPacketpool(ThreadVars *t, Packet *p)
SCMutexLock(&q->mutex_q);
PacketEnqueue(q, p);
SCCondSignal(&q->cond_q);
SCMutexUnlock(&q->mutex_q);
SCMutexLock(&mutex_pending);
//printf("TmqhOutputPacketpool: pending %" PRIu32 "\n", pending);
if (pending > 0) {
pending--;
if (proot) {
if (pending > 0) {
pending--;
} else {
printf("TmqhOutputPacketpool: warning, trying to subtract from 0 pending counter (tunnel root).\n");
}
}
} else {
printf("TmqhOutputPacketpool: warning, trying to subtract from 0 pending counter.\n");
}
if (pending <= max_pending_packets)
SCCondSignal(&cond_pending);
SCMutexUnlock(&mutex_pending);
}
/**

Loading…
Cancel
Save