From 83c75d01e00c88e4bdf26ae18f62649ec30933fc Mon Sep 17 00:00:00 2001 From: Gary Hsu Date: Thu, 9 Apr 2026 13:38:22 -0700 Subject: [PATCH 1/3] Move testing hooks under test_hooks::dispatcher namespace More specific namespace makes it clear these hooks are for testing the dispatcher's blocking_concurrent_queue, not general-purpose. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../threading/blocking_concurrent_queue.h | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/Source/Shared/arcana/threading/blocking_concurrent_queue.h b/Source/Shared/arcana/threading/blocking_concurrent_queue.h index ca6b6a7..aa0b25e 100644 --- a/Source/Shared/arcana/threading/blocking_concurrent_queue.h +++ b/Source/Shared/arcana/threading/blocking_concurrent_queue.h @@ -17,17 +17,20 @@ namespace arcana { #ifdef ARCANA_TESTING_HOOKS - namespace detail + namespace test_hooks::dispatcher { - inline std::function beforeWaitCallback{[]() {}}; - } + namespace detail + { + inline std::function beforeWaitCallback{[]() {}}; + } - // Set a callback to be invoked while holding the queue mutex, right before - // condition_variable::wait(). This is used for deterministic testing of - // lost-wakeup race conditions. Pass an empty lambda [](){} to reset. - inline void set_before_wait_callback(std::function callback) - { - detail::beforeWaitCallback = std::move(callback); + // Set a callback to be invoked while holding the queue mutex, right before + // condition_variable::wait(). This is used for deterministic testing of + // lost-wakeup race conditions. Pass an empty lambda [](){} to reset. + inline void set_before_wait_callback(std::function callback) + { + detail::beforeWaitCallback = std::move(callback); + } } #endif @@ -118,7 +121,7 @@ namespace arcana while (!cancel.cancelled() && m_data.empty()) { #ifdef ARCANA_TESTING_HOOKS - detail::beforeWaitCallback(); + test_hooks::dispatcher::detail::beforeWaitCallback(); #endif m_dataReady.wait(lock); } @@ -142,7 +145,7 @@ namespace arcana while (!cancel.cancelled() && m_data.empty()) { #ifdef ARCANA_TESTING_HOOKS - detail::beforeWaitCallback(); + test_hooks::dispatcher::detail::beforeWaitCallback(); #endif m_dataReady.wait(lock); } From 586b35ee0e3e9de85f1e3a7e27d90d8e3206494c Mon Sep 17 00:00:00 2001 From: Gary Hsu Date: Thu, 9 Apr 2026 15:28:19 -0700 Subject: [PATCH 2/3] Rename namespace to test_hooks::blocking_concurrent_queue The hook lives in blocking_concurrent_queue, not dispatcher. Using the accurate name makes it clear where the hook fires. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Shared/arcana/threading/blocking_concurrent_queue.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Shared/arcana/threading/blocking_concurrent_queue.h b/Source/Shared/arcana/threading/blocking_concurrent_queue.h index aa0b25e..88b8b5e 100644 --- a/Source/Shared/arcana/threading/blocking_concurrent_queue.h +++ b/Source/Shared/arcana/threading/blocking_concurrent_queue.h @@ -17,7 +17,7 @@ namespace arcana { #ifdef ARCANA_TESTING_HOOKS - namespace test_hooks::dispatcher + namespace test_hooks::blocking_concurrent_queue { namespace detail { @@ -121,7 +121,7 @@ namespace arcana while (!cancel.cancelled() && m_data.empty()) { #ifdef ARCANA_TESTING_HOOKS - test_hooks::dispatcher::detail::beforeWaitCallback(); + test_hooks::blocking_concurrent_queue::detail::beforeWaitCallback(); #endif m_dataReady.wait(lock); } @@ -145,7 +145,7 @@ namespace arcana while (!cancel.cancelled() && m_data.empty()) { #ifdef ARCANA_TESTING_HOOKS - test_hooks::dispatcher::detail::beforeWaitCallback(); + test_hooks::blocking_concurrent_queue::detail::beforeWaitCallback(); #endif m_dataReady.wait(lock); } @@ -167,4 +167,4 @@ namespace arcana mutable std::mutex m_mutex; std::condition_variable m_dataReady; }; -} \ No newline at end of file +} From a48b83c74b63dd7de57e719276657d135e9fc9bb Mon Sep 17 00:00:00 2001 From: Gary Hsu Date: Thu, 9 Apr 2026 15:29:42 -0700 Subject: [PATCH 3/3] Rename macro ARCANA_TESTING_HOOKS to ARCANA_TEST_HOOKS Consistent with the test_hooks namespace. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Shared/arcana/threading/blocking_concurrent_queue.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Shared/arcana/threading/blocking_concurrent_queue.h b/Source/Shared/arcana/threading/blocking_concurrent_queue.h index 88b8b5e..24d5276 100644 --- a/Source/Shared/arcana/threading/blocking_concurrent_queue.h +++ b/Source/Shared/arcana/threading/blocking_concurrent_queue.h @@ -10,13 +10,13 @@ #include #include -#ifdef ARCANA_TESTING_HOOKS +#ifdef ARCANA_TEST_HOOKS #include #endif namespace arcana { -#ifdef ARCANA_TESTING_HOOKS +#ifdef ARCANA_TEST_HOOKS namespace test_hooks::blocking_concurrent_queue { namespace detail @@ -120,7 +120,7 @@ namespace arcana { while (!cancel.cancelled() && m_data.empty()) { -#ifdef ARCANA_TESTING_HOOKS +#ifdef ARCANA_TEST_HOOKS test_hooks::blocking_concurrent_queue::detail::beforeWaitCallback(); #endif m_dataReady.wait(lock); @@ -144,7 +144,7 @@ namespace arcana { while (!cancel.cancelled() && m_data.empty()) { -#ifdef ARCANA_TESTING_HOOKS +#ifdef ARCANA_TEST_HOOKS test_hooks::blocking_concurrent_queue::detail::beforeWaitCallback(); #endif m_dataReady.wait(lock);