diff options
author | Xavi Hernandez <xhernandez@redhat.com> | 2018-11-27 12:21:01 +0100 |
---|---|---|
committer | Amar Tumballi <amarts@redhat.com> | 2018-11-28 03:09:28 +0000 |
commit | 6d69a663497ba2bb90b42eae8384cc57d6e4b283 (patch) | |
tree | f82ae4e10977809bcf89f089f90941f70b6112cb /libglusterfs | |
parent | 0a3540293bf2f4e96d79ca0d1baa168712472279 (diff) |
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 <xhernandez@redhat.com>
Diffstat (limited to 'libglusterfs')
-rw-r--r-- | libglusterfs/src/mem-pool.c | 13 |
1 files 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); |