From 225e86b37492e5004eb51498b46471d74f30841d Mon Sep 17 00:00:00 2001 From: Shehjar Tikoo Date: Fri, 3 Apr 2009 02:06:52 -0700 Subject: io-threads: Refactor un-ordered worker exit path This is being done for the same reason as the previous refactoring for ordered threads. Signed-off-by: Anand V. Avati --- xlators/performance/io-threads/src/io-threads.c | 50 +++++++++---------------- 1 file changed, 17 insertions(+), 33 deletions(-) (limited to 'xlators/performance') diff --git a/xlators/performance/io-threads/src/io-threads.c b/xlators/performance/io-threads/src/io-threads.c index a361def9f..b8cb633cd 100644 --- a/xlators/performance/io-threads/src/io-threads.c +++ b/xlators/performance/io-threads/src/io-threads.c @@ -1600,46 +1600,33 @@ iot_worker_ordered (void *arg) } /* Must be called with worker lock held. */ -int +gf_boolean_t iot_can_unordered_exit (iot_worker_t * worker) { - int allow_exit = 0; + gf_boolean_t allow_exit = _gf_false; iot_conf_t *conf = NULL; conf = worker->conf; - if (worker->queue_size > 0) - goto decided; - /* We dont want this thread to exit if its index is * below the min thread count. */ if (worker->thread_idx >= conf->min_u_threads) - allow_exit = 1; + allow_exit = _gf_true; -decided: return allow_exit; } -int +/* Must be called with worker lock held. */ +gf_boolean_t iot_unordered_exit (iot_worker_t *worker) { - int allow_exit = 0; - - /* It is possible that since the last time we timed out while - * waiting for a request, a new request has been added to this - * worker's request queue. Before we really exit, we must - * check for those requests. - */ - pthread_mutex_lock (&worker->qlock); - { - allow_exit = iot_can_unordered_exit (worker); + gf_boolean_t allow_exit = _gf_false; - if (allow_exit) { - worker->state = IOT_STATE_DEAD; - worker->thread = 0; - } + allow_exit = iot_can_unordered_exit (worker); + if (allow_exit) { + worker->state = IOT_STATE_DEAD; + worker->thread = 0; } - pthread_mutex_unlock (&worker->qlock); return allow_exit; } @@ -1651,6 +1638,7 @@ iot_unordered_request_wait (iot_worker_t * worker) struct timeval tv; struct timespec ts; int waitres = 0; + int retstat = 0; gettimeofday (&tv, NULL); ts.tv_sec = tv.tv_sec + worker->conf->u_idle_time; @@ -1662,9 +1650,10 @@ iot_unordered_request_wait (iot_worker_t * worker) waitres = pthread_cond_timedwait (&worker->dq_cond, &worker->qlock, &ts); if (waitres == ETIMEDOUT) - return -1; + if (iot_unordered_exit (worker)) + retstat = -1; - return 0; + return retstat; } @@ -1713,14 +1702,9 @@ iot_worker_unordered (void *arg) stub = iot_dequeue_unordered (worker); /* If no request was received, we must've timed out, - * if so, check if we can exit. - */ - if (stub == NULL) { - if (iot_unordered_exit (worker)) - break; - else - continue; - } + * and can exit. */ + if (stub == NULL) + break; call_resume (stub); } -- cgit