This is an automated email from the ASF dual-hosted git repository.

chenBright pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brpc.git


The following commit(s) were added to refs/heads/master by this push:
     new 3c559073 The MPSC queue should move the rvalue-reference argument into 
data_mem init (#3627)
3c559073 is described below

commit 3c559073cfa391efead44a19ba575bb7851aa9fa
Author: Dongsheng He <[email protected]>
AuthorDate: Tue Oct 20 10:35:50 2026 +0800

    The MPSC queue should move the rvalue-reference argument into data_mem init 
(#3627)
    
    * fix enqueue move-only
    
    * Add test for move-only enqueue and dequeue
    
    Added test for enqueueing and dequeuing move-only types in MPSCQueue.
    
    Co-authored-by: Copilot Autofix powered by AI 
<[email protected]>
    
    ---------
    
    Co-authored-by: Copilot Autofix powered by AI 
<[email protected]>
---
 src/butil/containers/mpsc_queue.h | 2 +-
 test/mpsc_queue_unittest.cc       | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/butil/containers/mpsc_queue.h 
b/src/butil/containers/mpsc_queue.h
index cbb48cb3..95c5a406 100644
--- a/src/butil/containers/mpsc_queue.h
+++ b/src/butil/containers/mpsc_queue.h
@@ -103,7 +103,7 @@ template <typename T, typename Alloc>
 void MPSCQueue<T, Alloc>::Enqueue(T&& data) {
     auto node = (MPSCQueueNode<T>*)_alloc.Alloc();
     node->next = MPSCQueueNode<T>::UNCONNECTED;
-    node->data_mem.Init(data);
+    node->data_mem.Init(std::move(data));
     EnqueueImpl(node);
 }
 
diff --git a/test/mpsc_queue_unittest.cc b/test/mpsc_queue_unittest.cc
index 800e45ae..97fb9ee4 100644
--- a/test/mpsc_queue_unittest.cc
+++ b/test/mpsc_queue_unittest.cc
@@ -158,6 +158,15 @@ TEST(MPSCQueueTest, destroys_dequeued_element) {
     ASSERT_EQ(0, DestructionTracked::alive);
 }
 
+TEST(MPSCQueueTest, enqueue_move_only) {
+  butil::MPSCQueue<std::unique_ptr<int>> q;
+  q.Enqueue(std::make_unique<int>(1));
+  std::unique_ptr<int> out;
+  ASSERT_TRUE(q.Dequeue(out));
+  ASSERT_NE(nullptr, out);
+  ASSERT_EQ(1, *out);
+}
+
 TEST(MPSCQueueTest, mpsc_test_allocator) {
     butil::ObjectPoolAllocator<MyObject> alloc;
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to