New approach for the empty packet queue issue. Now we just wait until it's no longer empty.

remotes/origin/master-1.0.x
Victor Julien 18 years ago
parent 2f6a186078
commit 982542cde6

@ -22,24 +22,18 @@ void PacketEnqueue (PacketQueue *q, Packet *p) {
#endif /* DBG_PERF */ #endif /* DBG_PERF */
} }
static u_int32_t dbg_packetdequeue = 0;
Packet *PacketDequeue (PacketQueue *q) { Packet *PacketDequeue (PacketQueue *q) {
Packet *p = q->bot; /* if the queue is empty there are no packets left.
if (p == NULL) { * In that case we sleep and try again. */
/* queue empty, alloc a new packet */ if (q->len == 0) {
p = malloc(sizeof(Packet)); printf("PacketDequeue: queue is empty, waiting...\n");
if (p == NULL) { usleep(100000); /* sleep 100ms */
printf("ERROR: malloc failed: %s\n", strerror(errno)); return PacketDequeue(q);
return NULL;
} }
CLEAR_TCP_PACKET(p); /* pull the bottom packet from the queue */
CLEAR_PACKET(p); Packet *p = q->bot;
dbg_packetdequeue++;
printf("PacketDequeue: alloced a new packet. MAX_PENDING %u, extra alloc: %u\n", MAX_PENDING, dbg_packetdequeue);
} else {
/* more packets in queue */ /* more packets in queue */
if (q->bot->prev != NULL) { if (q->bot->prev != NULL) {
q->bot = q->bot->prev; q->bot = q->bot->prev;
@ -49,9 +43,8 @@ Packet *PacketDequeue (PacketQueue *q) {
q->top = NULL; q->top = NULL;
q->bot = NULL; q->bot = NULL;
} }
q->len--; q->len--;
}
p->next = NULL; p->next = NULL;
p->prev = NULL; p->prev = NULL;
return p; return p;

Loading…
Cancel
Save