summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShehjar Tikoo <shehjart@zresearch.com>2009-04-03 02:06:52 -0700
committerAnand V. Avati <avati@amp.gluster.com>2009-04-08 11:57:15 +0530
commit225e86b37492e5004eb51498b46471d74f30841d (patch)
tree99eb49e257204045cd579463d2680fd1743b64c8
parentfe1cedc1a960493337676885881018e4687c12a2 (diff)
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 <avati@amp.gluster.com>
-rw-r--r--xlators/performance/io-threads/src/io-threads.c50
1 files changed, 17 insertions, 33 deletions
diff --git a/xlators/performance/io-threads/src/io-threads.c b/xlators/performance/io-threads/src/io-threads.c
index a361def9f6d..b8cb633cdeb 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);
}