Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/butil/containers/mpsc_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ template <typename T>
class ObjectPoolAllocator {
public:
void* Alloc() { return get_object<MPSCQueueNode<T>>(); }
void Free(void* p) { return_object(p); }
void Free(void* p) { return_object(static_cast<MPSCQueueNode<T>*>(p)); }
};


Expand Down
22 changes: 21 additions & 1 deletion test/mpsc_queue_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#include <pthread.h>
#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;
Expand Down Expand Up @@ -120,5 +123,22 @@ TEST(MPSCQueueTest, mpsc_multi_thread) {

}

struct MyObject {};

TEST(MPSCQueueTest, mpsc_test_allocator) {
butil::ObjectPoolAllocator<MyObject> alloc;

auto p = alloc.Alloc();
butil::ObjectPoolInfo info = butil::describe_objects<butil::MPSCQueueNode<MyObject>>();
ASSERT_EQ(1, info.item_num);

alloc.Free(p);
info = butil::describe_objects<butil::MPSCQueueNode<MyObject>>();
ASSERT_EQ(1, info.item_num);

}
p = alloc.Alloc();
info = butil::describe_objects<butil::MPSCQueueNode<MyObject>>();
ASSERT_EQ(1, info.item_num);
}

}