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

wwbmmm 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 bc6ce691 refactor: consolidate MPSCQueue enqueue paths (#3655)
bc6ce691 is described below

commit bc6ce6915556ff731d0fd3997c7903c26b6fbac8
Author: nkysg <[email protected]>
AuthorDate: Sun Oct 25 17:17:56 2026 +0800

    refactor: consolidate MPSCQueue enqueue paths (#3655)
---
 src/butil/containers/mpsc_queue.h | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/butil/containers/mpsc_queue.h 
b/src/butil/containers/mpsc_queue.h
index 95c5a406..ff5aee0b 100644
--- a/src/butil/containers/mpsc_queue.h
+++ b/src/butil/containers/mpsc_queue.h
@@ -74,6 +74,9 @@ public:
     bool Dequeue(T& data);
 
 private:
+    template <typename U>
+    void EnqueueInternal(U&& data);
+
     // Reverse the list until old_head.
     void ReverseList(MPSCQueueNode<T>* old_head);
 
@@ -93,17 +96,20 @@ MPSCQueue<T, Alloc>::~MPSCQueue() {
 
 template <typename T, typename Alloc>
 void MPSCQueue<T, Alloc>::Enqueue(typename add_const_reference<T>::type data) {
-    auto node = (MPSCQueueNode<T>*)_alloc.Alloc();
-    node->next = MPSCQueueNode<T>::UNCONNECTED;
-    node->data_mem.Init(data);
-    EnqueueImpl(node);
+    EnqueueInternal(data);
 }
 
 template <typename T, typename Alloc>
 void MPSCQueue<T, Alloc>::Enqueue(T&& data) {
+    EnqueueInternal(std::move(data));
+}
+
+template <typename T, typename Alloc>
+template <typename U>
+void MPSCQueue<T, Alloc>::EnqueueInternal(U&& data) {
     auto node = (MPSCQueueNode<T>*)_alloc.Alloc();
     node->next = MPSCQueueNode<T>::UNCONNECTED;
-    node->data_mem.Init(std::move(data));
+    node->data_mem.Init(std::forward<U>(data));
     EnqueueImpl(node);
 }
 


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

Reply via email to