diff --git a/src/flow-queue.c b/src/flow-queue.c index ca2bdc3178..bfd2365f2e 100644 --- a/src/flow-queue.c +++ b/src/flow-queue.c @@ -136,49 +136,41 @@ Flow *FlowDequeue (FlowQueue *q) { * \brief Transfer a flow from one queue to another * * \param f the flow to be transfered - * \param srcq the source queue, where the flow will be removed. The param may - * be NULL. + * \param srcq the source queue, where the flow will be removed. * \param dstq the dest queue where the flow will be placed * + * \note srcq and dstq must be different queues. */ void FlowRequeue(Flow *f, FlowQueue *srcq, FlowQueue *dstq) { #ifdef DEBUG - BUG_ON(dstq == NULL); + BUG_ON(srcq == NULL || dstq == NULL || srcq == dstq); #endif /* DEBUG */ - if (srcq != NULL) { - 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 != NULL) - f->lprev->lnext = f->lnext; /* remove from flow prev */ - if (f->lnext != NULL) - f->lnext->lprev = f->lprev; /* remove from flow next */ + /* 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 != NULL) + f->lprev->lnext = f->lnext; /* remove from flow prev */ + if (f->lnext != NULL) + f->lnext->lprev = f->lprev; /* remove from flow next */ #ifdef DEBUG - BUG_ON(srcq->len == 0); + BUG_ON(srcq->len == 0); #endif - if (srcq->len > 0) - srcq->len--; /* adjust len */ + if (srcq->len > 0) + srcq->len--; /* adjust len */ - f->lnext = NULL; - f->lprev = NULL; + f->lnext = NULL; + f->lprev = NULL; - /* don't unlock if src and dst are the same */ - if (srcq != dstq) { - SCMutexUnlock(&srcq->mutex_q); - } - } + SCMutexUnlock(&srcq->mutex_q); - /* now put it in dst */ - if (srcq != dstq) { - SCMutexLock(&dstq->mutex_q); - } + SCMutexLock(&dstq->mutex_q); /* add to new queue (append) */ f->lprev = dstq->bot;