diff options
author | Simo Sorce <simo@redhat.com> | 2012-02-23 10:42:21 -0500 |
---|---|---|
committer | Simo Sorce <simo@redhat.com> | 2012-02-23 16:53:00 -0500 |
commit | e932bf74e59530ca6cefdccd3979b3f7fa862268 (patch) | |
tree | fc81e283081ba9e6bc5b26fda95f27912a86fe0e | |
parent | ee9b3fc03fffb13225f2217303a18bc7703e6dbf (diff) | |
download | gss-proxy-e932bf74e59530ca6cefdccd3979b3f7fa862268.tar.gz gss-proxy-e932bf74e59530ca6cefdccd3979b3f7fa862268.tar.xz gss-proxy-e932bf74e59530ca6cefdccd3979b3f7fa862268.zip |
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.
-rw-r--r-- | proxy/src/gp_workers.c | 28 |
1 files changed, 13 insertions, 15 deletions
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); |