From aa4ed2d28d91d31be85799ffd839e8f14928fd9a Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Thu, 8 Dec 2016 16:31:23 +0200 Subject: [PATCH] Only add DCBs to the list that arean't in the list Listeners are added to the list multiple times due to how DCBs are removed from the list. This requires that an additional check is made so that we are sure a DCB will not be added to the list twice. --- server/core/dcb.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/server/core/dcb.c b/server/core/dcb.c index 8ac2fd1f7..32bb2891c 100644 --- a/server/core/dcb.c +++ b/server/core/dcb.c @@ -3415,20 +3415,30 @@ void dcb_append_readqueue(DCB *dcb, GWBUF *buffer) void dcb_add_to_list(DCB *dcb) { - spinlock_acquire(&all_dcbs_lock[dcb->thread.id]); - - if (all_dcbs[dcb->thread.id] == NULL) + if (dcb->dcb_role != DCB_ROLE_SERVICE_LISTENER || + (dcb->thread.next == NULL && dcb->thread.tail == NULL)) { - all_dcbs[dcb->thread.id] = dcb; - all_dcbs[dcb->thread.id]->thread.tail = dcb; - } - else - { - all_dcbs[dcb->thread.id]->thread.tail->thread.next = dcb; - all_dcbs[dcb->thread.id]->thread.tail = dcb; - } + /** + * This is a DCB which is either not a listener or it is a listener which + * is not in the list. Stopped listeners are not removed from the list + * as that part is done in the final zombie processing. + */ - spinlock_release(&all_dcbs_lock[dcb->thread.id]); + spinlock_acquire(&all_dcbs_lock[dcb->thread.id]); + + if (all_dcbs[dcb->thread.id] == NULL) + { + all_dcbs[dcb->thread.id] = dcb; + all_dcbs[dcb->thread.id]->thread.tail = dcb; + } + else + { + all_dcbs[dcb->thread.id]->thread.tail->thread.next = dcb; + all_dcbs[dcb->thread.id]->thread.tail = dcb; + } + + spinlock_release(&all_dcbs_lock[dcb->thread.id]); + } } /**