From ddb493f63ec2f2521ba3f511ba894fcc55190cd7 Mon Sep 17 00:00:00 2001 From: liqiang Date: Thu, 6 Jan 2022 16:09:20 +0800 Subject: [PATCH] Use thread-local pointer variables to save the shard location required by this thread. Signed-off-by: liqiang --- src/common/mempool.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/common/mempool.cc b/src/common/mempool.cc index e4ab5d4a10a..669ea192167 100644 --- a/src/common/mempool.cc +++ b/src/common/mempool.cc @@ -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( -- 2.39.5