[stgt] [PATCH 1/3] simplify the failure cleanup path of the backing store ack thread

FUJITA Tomonori fujita.tomonori at lab.ntt.co.jp
Tue Dec 23 13:23:23 CET 2008


We don't need pthread_cancel and pthread_cond_signal here.

Signed-off-by: FUJITA Tomonori <fujita.tomonori at lab.ntt.co.jp>
---
 usr/bs.c |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/usr/bs.c b/usr/bs.c
index 542ef55..e659438 100644
--- a/usr/bs.c
+++ b/usr/bs.c
@@ -68,6 +68,9 @@ retry:
 		goto out;
 	}
 
+	if (info->stop)
+		goto out;
+
 	pthread_mutex_lock(&info->finished_lock);
 retest:
 	if (list_empty(&info->finished_list)) {
@@ -100,7 +103,7 @@ rewrite:
 
 	goto retry;
 out:
-	return NULL;
+	pthread_exit(NULL);
 }
 
 static void bs_thread_request_done(int fd, int events, void *data)
@@ -203,8 +206,10 @@ int bs_thread_open(struct bs_thread_info *info, request_func_t *rfn,
 		goto close_done_fd;
 
 	ret = pthread_create(&info->ack_thread, NULL, bs_thread_ack_fn, info);
-	if (ret)
+	if (ret) {
+		eprintf("failed to create an ack thread, %s\n", strerror(ret));
 		goto event_del;
+	}
 
 	if (nr_threads > ARRAY_SIZE(info->worker_thread)) {
 		eprintf("too many threads %d\n", nr_threads);
@@ -228,12 +233,10 @@ rewrite:
 
 	return 0;
 destroy_threads:
+	info->stop = 1;
 	write(info->command_fd[1], &ret, sizeof(ret));
-	pthread_cancel(info->ack_thread);
-	pthread_cond_signal(&info->finished_cond);
 	pthread_join(info->ack_thread, NULL);
 
-	info->stop = 1;
 	for (i = 0; info->worker_thread[i]; i++) {
 		pthread_cancel(info->worker_thread[i]);
 		pthread_cond_signal(&info->pending_cond);
-- 
1.5.5.GIT

--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html



More information about the stgt mailing list