From e932bf74e59530ca6cefdccd3979b3f7fa862268 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Thu, 23 Feb 2012 10:42:21 -0500 Subject: workers: Fix handling of workers query handling Chekcing for query == NULL outside of the mutex was wrong as it may make us end up restarting operation on the value of q we just handed back as if it was a new query. We just need to always go through the conditional lock. --- proxy/src/gp_workers.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'proxy') diff --git a/proxy/src/gp_workers.c b/proxy/src/gp_workers.c index 1191221..1a58136 100644 --- a/proxy/src/gp_workers.c +++ b/proxy/src/gp_workers.c @@ -378,24 +378,22 @@ static void *gp_worker_main(void *pvt) while (!t->pool->shutdown) { - /* wait for next query */ - if (t->query == NULL) { - /* ======> COND_MUTEX */ - pthread_mutex_lock(&t->cond_mutex); - while (t->query == NULL) { - pthread_cond_wait(&t->cond_wakeup, &t->cond_mutex); - if (t->pool->shutdown) { - pthread_exit(NULL); - } + /* ======> COND_MUTEX */ + pthread_mutex_lock(&t->cond_mutex); + while (t->query == NULL) { + /* wait for next query */ + pthread_cond_wait(&t->cond_wakeup, &t->cond_mutex); + if (t->pool->shutdown) { + pthread_exit(NULL); } + } - /* grab the query off the shared pointer */ - q = t->query; - t->query = NULL; + /* grab the query off the shared pointer */ + q = t->query; + t->query = NULL; - /* <====== COND_MUTEX */ - pthread_mutex_unlock(&t->cond_mutex); - } + /* <====== COND_MUTEX */ + pthread_mutex_unlock(&t->cond_mutex); /* handle the client request */ gp_handle_query(t->pool, q); -- cgit