Skip to content

Commit fa054fd

Browse files
bghgaryCopilot
andcommitted
Add optional testing hook for blocking_concurrent_queue
Add a global before-wait callback invoked while holding the queue mutex, right before condition_variable::wait(). This enables deterministic testing of lost-wakeup race conditions in code that uses the queue. Behind #ifdef ARCANA_TESTING_HOOKS -- zero cost when not enabled. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 53e5b05 commit fa054fd

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Source/Shared/arcana/threading/blocking_concurrent_queue.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
#include <queue>
88
#include <condition_variable>
99

10+
#ifdef ARCANA_TESTING_HOOKS
11+
#include <functional>
12+
inline std::function<void()> g_beforeWaitCallback{[]() {}};
13+
#endif
14+
1015
namespace arcana
1116
{
1217
template<typename T, size_t max_size = std::numeric_limits<size_t>::max()>
@@ -95,6 +100,9 @@ namespace arcana
95100
{
96101
while (!cancel.cancelled() && m_data.empty())
97102
{
103+
#ifdef ARCANA_TESTING_HOOKS
104+
g_beforeWaitCallback();
105+
#endif
98106
m_dataReady.wait(lock);
99107
}
100108
}
@@ -116,6 +124,9 @@ namespace arcana
116124
{
117125
while (!cancel.cancelled() && m_data.empty())
118126
{
127+
#ifdef ARCANA_TESTING_HOOKS
128+
g_beforeWaitCallback();
129+
#endif
119130
m_dataReady.wait(lock);
120131
}
121132
}

0 commit comments

Comments
 (0)