From 7b864f917ee5ad77a23d77863fb6b7eb2c0b6a19 Mon Sep 17 00:00:00 2001 From: lqx Date: Tue, 17 Dec 2024 21:12:34 +0800 Subject: [PATCH] fix review --- include/pika_client_conn.h | 4 ++-- src/net/src/memory_pool.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/pika_client_conn.h b/include/pika_client_conn.h index e5b207a70..9a8998337 100644 --- a/include/pika_client_conn.h +++ b/include/pika_client_conn.h @@ -116,7 +116,7 @@ class PikaClientConn : public net::RedisConn { std::shared_ptr time_stat_; - void SetMemoryPool(net::MemoryPool *memory_pool) override{ memory_pool_ = memory_pool; } + void SetMemoryPool(net::MemoryPool* memory_pool) override { memory_pool_ = memory_pool; } private: net::ServerThread* const server_thread_; @@ -131,7 +131,7 @@ class PikaClientConn : public net::RedisConn { bool authenticated_ = false; std::shared_ptr user_; - net::MemoryPool *memory_pool_; + net::MemoryPool *memory_pool_= nullptr; std::variant, Cmd*> DoCmd(const PikaCmdArgsType& argv, const std::string& opt, const std::shared_ptr& resp_ptr, bool cache_miss_in_rtc); diff --git a/src/net/src/memory_pool.h b/src/net/src/memory_pool.h index 229b3776d..499f9570c 100644 --- a/src/net/src/memory_pool.h +++ b/src/net/src/memory_pool.h @@ -93,13 +93,13 @@ class MemoryPool { } auto index = *page; - bits_ &= ~(1ull << index); + bits_.fetch_and(~(1ull << index)); } private: template T *AllocateExtend(Args &&...args) { - auto newPage = std::malloc(sizeof(T) + pageOffset_); + auto newPage = std::aligned_alloc(alignof(T), sizeof(T) + pageOffset_); auto page = reinterpret_cast(newPage); *page = extendFlag_; // Set the page head to 0xFF return new (++page) T(std::forward(args)...);