diff --git a/mooncake-store/include/offset_allocator/offset_allocator.hpp b/mooncake-store/include/offset_allocator/offset_allocator.hpp index fde978ba..b6d55c8d 100644 --- a/mooncake-store/include/offset_allocator/offset_allocator.hpp +++ b/mooncake-store/include/offset_allocator/offset_allocator.hpp @@ -173,7 +173,7 @@ class OffsetAllocator : public std::enable_shared_from_this { // Internal method to get metrics without locking (caller must hold m_mutex) [[nodiscard]] - OffsetAllocatorMetrics get_metrics_internal() const; + OffsetAllocatorMetrics get_metrics_internal() const REQUIRES(m_mutex); std::unique_ptr<__Allocator> m_allocator GUARDED_BY(m_mutex); uint64_t m_base; diff --git a/mooncake-store/tests/offset_allocator_test.cpp b/mooncake-store/tests/offset_allocator_test.cpp index d255b538..5b1d7eb6 100644 --- a/mooncake-store/tests/offset_allocator_test.cpp +++ b/mooncake-store/tests/offset_allocator_test.cpp @@ -1,4 +1,5 @@ #include "offset_allocator/offset_allocator.hpp" +#include "mutex.h" #include "serializer.h" #include "types.h" @@ -297,6 +298,8 @@ class OffsetAllocatorTest : public ::testing::Test { void assertAllocatorEQ(const std::shared_ptr& a, const std::shared_ptr& b) { + MutexLocker lock_a(&a->m_mutex); + MutexLocker lock_b(&b->m_mutex); // Compare basic member variables ASSERT_EQ(a->m_base, b->m_base); ASSERT_EQ(a->m_multiplier_bits, b->m_multiplier_bits); @@ -353,6 +356,8 @@ class OffsetAllocatorTest : public ::testing::Test { // Compare two allocators bytes by bytes to detect one bit difference. bool isAllocatorEqual(const std::shared_ptr& a, const std::shared_ptr& b) { + MutexLocker lock_a(&a->m_mutex); + MutexLocker lock_b(&b->m_mutex); // Compare basic member variables if (memcmp(&a->m_base, &b->m_base, sizeof(a->m_base)) != 0) return false;