]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
Use thread-local pointer variables to save the shard location required by this thread.
authorliqiang <liqiang64@huawei.com>
Thu, 6 Jan 2022 08:09:20 +0000 (16:09 +0800)
committerliqiang <liqiang64@huawei.com>
Thu, 6 Jan 2022 08:09:20 +0000 (16:09 +0800)
Signed-off-by: liqiang <liqiang64@huawei.com>
src/common/mempool.cc

index e4ab5d4a10ad17aec05754ae236e07b77211a5ff..669ea192167c4df54823ae13f2384cefcd6c72da 100644 (file)
@@ -15,7 +15,7 @@
 #include "include/mempool.h"
 #include "include/demangle.h"
 
-
+static thread_local mempool::shard_t *thread_shard = NULL;
 // default to debug_mode off
 bool mempool::debug_mode = false;
 
@@ -92,9 +92,9 @@ size_t mempool::pool_t::allocated_items() const
 
 void mempool::pool_t::adjust_count(ssize_t items, ssize_t bytes)
 {
-  shard_t *shard = pick_a_shard();
-  shard->items += items;
-  shard->bytes += bytes;
+  thread_shard = (thread_shard == NULL) ? pick_a_shard() : thread_shard;
+  thread_shard->items += items;
+  thread_shard->bytes += bytes;
 }
 
 void mempool::pool_t::get_stats(