From b85a004e68787184e7f2c9689b6a637deaaf06fe Mon Sep 17 00:00:00 2001 From: jlxjiang Date: Fri, 13 Mar 2026 13:51:43 +0800 Subject: [PATCH] align try_push default forwarding and add coverage --- src/babylon/concurrent/bounded_queue.hpp | 4 ++-- test/concurrent/test_bounded_queue.cpp | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/babylon/concurrent/bounded_queue.hpp b/src/babylon/concurrent/bounded_queue.hpp index b67a9d49..da6ee676 100644 --- a/src/babylon/concurrent/bounded_queue.hpp +++ b/src/babylon/concurrent/bounded_queue.hpp @@ -465,14 +465,14 @@ template ::value, int>::type> inline bool ABSL_ATTRIBUTE_ALWAYS_INLINE ConcurrentBoundedQueue::try_push(U&& value) noexcept { - return try_push(::std::forward(value)); + return try_push(::std::forward(value)); } template template inline bool ABSL_ATTRIBUTE_ALWAYS_INLINE ConcurrentBoundedQueue::try_push(C&& callback) noexcept { - return try_push(::std::forward(callback)); + return try_push(::std::forward(callback)); } template diff --git a/test/concurrent/test_bounded_queue.cpp b/test/concurrent/test_bounded_queue.cpp index 3acbf4a7..229e7c9d 100644 --- a/test/concurrent/test_bounded_queue.cpp +++ b/test/concurrent/test_bounded_queue.cpp @@ -85,6 +85,22 @@ TEST(concurrent_bounded_queue, try_pop_fail_on_empty) { ASSERT_EQ("10010", s); } +TEST(concurrent_bounded_queue, try_push_default_overload) { + ConcurrentBoundedQueue<::std::string> queue(1); + ASSERT_TRUE(queue.try_push("10086")); + ASSERT_FALSE(queue.try_push("10010")); + ::std::string s; + ASSERT_TRUE(queue.try_pop(s)); + ASSERT_EQ("10086", s); + bool called = false; + ASSERT_TRUE(queue.try_push([&](::std::string& value) { + called = true; + value = "10010"; + })); + ASSERT_TRUE(called); + ASSERT_TRUE(queue.try_pop(s)); +} + TEST(concurrent_bounded_queue, try_pop_wakeup_blocking_push) { ConcurrentBoundedQueue<::std::string> queue; queue.push("10086");