From 6d69a663497ba2bb90b42eae8384cc57d6e4b283 Mon Sep 17 00:00:00 2001 From: Xavi Hernandez Date: Tue, 27 Nov 2018 12:21:01 +0100 Subject: mem-pool: minor fix and clarification A comment has been added to pool_destructor() function to explain why locks are not needed there. Also, the initialization of 'poison' field has been moved inside a locked region for further safety and clarity. Change-Id: Idbf23bda7f9228d60c644a1bea4b6c2cfc582090 updates: bz#1193929 Signed-off-by: Xavi Hernandez --- libglusterfs/src/mem-pool.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/libglusterfs/src/mem-pool.c b/libglusterfs/src/mem-pool.c index ec8e40d2bc0..4ef62b8da48 100644 --- a/libglusterfs/src/mem-pool.c +++ b/libglusterfs/src/mem-pool.c @@ -527,7 +527,15 @@ pool_destructor(void *arg) { per_thread_pool_list_t *pool_list = arg; - /* The pool-sweeper thread will take it from here. */ + /* The pool-sweeper thread will take it from here. + * + * We can change 'poison' here without taking locks because the change + * itself doesn't interact with other parts of the code and a simple write + * is already atomic from the point of view of the processor. + * + * This change can modify what mem_put() does, but both possibilities are + * fine until the sweeper thread kicks in. The real synchronization must be + * between mem_put() and the sweeper thread. */ pool_list->poison = 1; } @@ -789,9 +797,8 @@ mem_get_pool_list(void) } } - pool_list->poison = 0; - (void)pthread_mutex_lock(&pool_lock); + pool_list->poison = 0; list_add(&pool_list->thr_list, &pool_threads); (void)pthread_mutex_unlock(&pool_lock); -- cgit