diff --git a/src/butil/containers/mpsc_queue.h b/src/butil/containers/mpsc_queue.h index 45ab2ebe04..f9e1d78099 100644 --- a/src/butil/containers/mpsc_queue.h +++ b/src/butil/containers/mpsc_queue.h @@ -52,7 +52,7 @@ template class ObjectPoolAllocator { public: void* Alloc() { return get_object>(); } - void Free(void* p) { return_object(p); } + void Free(void* p) { return_object(static_cast*>(p)); } }; diff --git a/test/mpsc_queue_unittest.cc b/test/mpsc_queue_unittest.cc index bd152a5d71..f57a85f620 100644 --- a/test/mpsc_queue_unittest.cc +++ b/test/mpsc_queue_unittest.cc @@ -2,6 +2,9 @@ #include #include "butil/containers/mpsc_queue.h" +#define BAIDU_CLEAR_OBJECT_POOL_AFTER_ALL_THREADS_QUIT +#include "butil/object_pool.h" + namespace { const uint MAX_COUNT = 1000000; @@ -120,5 +123,22 @@ TEST(MPSCQueueTest, mpsc_multi_thread) { } +struct MyObject {}; + +TEST(MPSCQueueTest, mpsc_test_allocator) { + butil::ObjectPoolAllocator alloc; + + auto p = alloc.Alloc(); + butil::ObjectPoolInfo info = butil::describe_objects>(); + ASSERT_EQ(1, info.item_num); + + alloc.Free(p); + info = butil::describe_objects>(); + ASSERT_EQ(1, info.item_num); -} \ No newline at end of file + p = alloc.Alloc(); + info = butil::describe_objects>(); + ASSERT_EQ(1, info.item_num); +} + +}