From fbbdbb251fdf49e76e8a97ccb5ecabe504fc1ba8 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Wed, 7 Dec 2011 10:19:51 +0100 Subject: [PATCH] flow engine: remove unneeded 'need_srclock' argument for FlowRequeue --- src/flow-hash.c | 4 ++-- src/flow-queue.c | 22 ++++++++++++---------- src/flow-queue.h | 3 ++- src/flow.c | 6 +++--- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/flow-hash.c b/src/flow-hash.c index 47e5caae7d..2a9f66ca12 100644 --- a/src/flow-hash.c +++ b/src/flow-hash.c @@ -405,7 +405,7 @@ Flow *FlowGetFlowFromHash (Packet *p) f->flags |= FLOW_NEW_LIST; f->fb = fb; - FlowRequeue(f, NULL, &flow_new_q[f->protomap], 1); + FlowRequeue(f, NULL, &flow_new_q[f->protomap]); SCSpinUnlock(&fb->s); FlowHashCountUpdate; @@ -443,7 +443,7 @@ Flow *FlowGetFlowFromHash (Packet *p) f->flags |= FLOW_NEW_LIST; f->fb = fb; - FlowRequeue(f, NULL, &flow_new_q[f->protomap], 1); + FlowRequeue(f, NULL, &flow_new_q[f->protomap]); SCSpinUnlock(&fb->s); FlowHashCountUpdate; diff --git a/src/flow-queue.c b/src/flow-queue.c index 7c0e63f697..9e073a9b3c 100644 --- a/src/flow-queue.c +++ b/src/flow-queue.c @@ -116,36 +116,38 @@ Flow *FlowDequeue (FlowQueue *q) { * \param srcq the source queue, where the flow will be removed. The param may * be NULL. * \param dstq the dest queue where the flow will be placed - * \param need_srclock does the srcq need locking? 1 yes, 0 no * */ -void FlowRequeue(Flow *f, FlowQueue *srcq, FlowQueue *dstq, uint8_t need_srclock) +void FlowRequeue(Flow *f, FlowQueue *srcq, FlowQueue *dstq) { #ifdef DEBUG BUG_ON(dstq == NULL); #endif /* DEBUG */ if (srcq != NULL) { - if (need_srclock == 1) { - SCMutexLock(&srcq->mutex_q); - } + SCMutexLock(&srcq->mutex_q); + /* remove from old queue */ if (srcq->top == f) srcq->top = f->lnext; /* remove from queue top */ if (srcq->bot == f) srcq->bot = f->lprev; /* remove from queue bot */ - if (f->lprev) + if (f->lprev != NULL) f->lprev->lnext = f->lnext; /* remove from flow prev */ - if (f->lnext) + if (f->lnext != NULL) f->lnext->lprev = f->lprev; /* remove from flow next */ - srcq->len--; /* adjust len */ +#ifdef DEBUG + BUG_ON(srcq->len == 0); +#endif + if (srcq->len > 0) + srcq->len--; /* adjust len */ f->lnext = NULL; f->lprev = NULL; /* don't unlock if src and dst are the same */ - if (srcq != dstq && need_srclock == 1) { + if (srcq != dstq) { SCMutexUnlock(&srcq->mutex_q); } } @@ -157,7 +159,7 @@ void FlowRequeue(Flow *f, FlowQueue *srcq, FlowQueue *dstq, uint8_t need_srclock /* add to new queue (append) */ f->lprev = dstq->bot; - if (f->lprev) + if (f->lprev != NULL) f->lprev->lnext = f; f->lnext = NULL; dstq->bot = f; diff --git a/src/flow-queue.h b/src/flow-queue.h index 3dc2e77d7c..57ca310a07 100644 --- a/src/flow-queue.h +++ b/src/flow-queue.h @@ -47,7 +47,8 @@ void FlowQueueDestroy (FlowQueue *); void FlowEnqueue (FlowQueue *, Flow *); Flow *FlowDequeue (FlowQueue *); -void FlowRequeue(Flow *, FlowQueue *, FlowQueue *, uint8_t); + +void FlowRequeue(Flow *, FlowQueue *, FlowQueue *); void FlowRequeueMoveToBot(Flow *, FlowQueue *); void FlowRequeueMoveToSpare(Flow *, FlowQueue *); diff --git a/src/flow.c b/src/flow.c index 6d65a294b8..ff715f3086 100644 --- a/src/flow.c +++ b/src/flow.c @@ -107,7 +107,7 @@ void FlowUpdateQueue(Flow *f) /* in the new list -- we consider a flow no longer * new if we have seen at least 2 pkts in both ways. */ if (f->flags & FLOW_TO_DST_SEEN && f->flags & FLOW_TO_SRC_SEEN) { - FlowRequeue(f, &flow_new_q[f->protomap], &flow_est_q[f->protomap], 1); + FlowRequeue(f, &flow_new_q[f->protomap], &flow_est_q[f->protomap]); f->flags |= FLOW_EST_LIST; /* transition */ f->flags &= ~FLOW_NEW_LIST; @@ -122,7 +122,7 @@ void FlowUpdateQueue(Flow *f) f->flags &=~ FLOW_EST_LIST; SCLogDebug("flow %p was put into closing queue ts %"PRIuMAX"", f, (uintmax_t)f->lastts_sec); - FlowRequeue(f, &flow_est_q[f->protomap], &flow_close_q[f->protomap], 1); + FlowRequeue(f, &flow_est_q[f->protomap], &flow_close_q[f->protomap]); } else { /* Pull and put back -- this way the flows on * top of the list are least recently used. */ @@ -144,7 +144,7 @@ void FlowUpdateQueue(Flow *f) f->flags &=~ FLOW_CLOSED_LIST; SCLogDebug("flow %p was put into new queue ts %"PRIuMAX"", f, (uintmax_t)f->lastts_sec); - FlowRequeue(f, &flow_close_q[f->protomap], &flow_new_q[f->protomap], 1); + FlowRequeue(f, &flow_close_q[f->protomap], &flow_new_q[f->protomap]); } else { /* Pull and put back -- this way the flows on * top of the list are least recently used. */