]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
Thread local variables should hold the index of the thread, not the shard[] pointer...
authorliqiang <liqiang64@huawei.com>
Fri, 7 Jan 2022 03:03:48 +0000 (11:03 +0800)
committerliqiang <liqiang64@huawei.com>
Fri, 7 Jan 2022 03:03:48 +0000 (11:03 +0800)
Signed-off-by: liqiang <liqiang64@huawei.com>
src/common/mempool.cc

index 70b58635067b88df865862801120575738c4607c..79354f70821617737d06beeaacaabe4a58bafb95 100644 (file)
 #include "include/mempool.h"
 #include "include/demangle.h"
 
-static thread_local mempool::shard_t *thread_shard = nullptr;
+// Thread local variables should save index, not &shard[index],
+// because shard[] is defined in the class
+static thread_local size_t thread_shard_index = mempool::num_shards;
+
 // default to debug_mode off
 bool mempool::debug_mode = false;
 
@@ -92,9 +95,9 @@ size_t mempool::pool_t::allocated_items() const
 
 void mempool::pool_t::adjust_count(ssize_t items, ssize_t bytes)
 {
-  thread_shard = (thread_shard == nullptr) ? pick_a_shard() : thread_shard;
-  thread_shard->items += items;
-  thread_shard->bytes += bytes;
+  thread_shard_index = (thread_shard_index == num_shards) ? pick_a_shard_int() : thread_shard_index;
+  shard[thread_shard_index].items += items;
+  shard[thread_shard_index].bytes += bytes;
 }
 
 void mempool::pool_t::get_stats(