@@ -116,7 +116,7 @@ namespace bridge_util {
116
116
117
117
// Returns a ref to the first element in the queue
118
118
// Note: Blocks if the queue is empty
119
- const T& peek (Result& result, const DWORD timeoutMS = 0 ) const {
119
+ const T& peek (Result& result, const DWORD timeoutMS = 0 , std::atomic< bool >* const pbEarlyOutSignal = nullptr ) const {
120
120
ULONGLONG start = 0 , curTick;
121
121
do {
122
122
const auto currentWrite = m_write->load (std::memory_order_relaxed);
@@ -131,6 +131,11 @@ namespace bridge_util {
131
131
132
132
curTick = GetTickCount64 ();
133
133
start = start > 0 ? start : curTick;
134
+
135
+ if (pbEarlyOutSignal && pbEarlyOutSignal->load ()) {
136
+ result = Result::Timeout;
137
+ return m_default;
138
+ }
134
139
} while (timeoutMS == 0 || start + timeoutMS > curTick);
135
140
136
141
result = Result::Timeout;
@@ -140,7 +145,7 @@ namespace bridge_util {
140
145
141
146
// Returns a copy to the first element in queue, AND removes it
142
147
// Note: Blocks if queue is empty
143
- const T& pull (Result& result, const DWORD timeoutMS = 0 ) {
148
+ const T& pull (Result& result, const DWORD timeoutMS = 0 , std::atomic< bool >* const pbEarlyOutSignal = nullptr ) {
144
149
ULONGLONG start = 0 , curTick;
145
150
do {
146
151
const auto currentWrite = m_write->load (std::memory_order_relaxed);
@@ -156,6 +161,11 @@ namespace bridge_util {
156
161
157
162
curTick = GetTickCount64 ();
158
163
start = start > 0 ? start : curTick;
164
+
165
+ if (pbEarlyOutSignal && pbEarlyOutSignal->load ()) {
166
+ result = Result::Timeout;
167
+ return m_default;
168
+ }
159
169
} while (timeoutMS == 0 || start + timeoutMS > curTick);
160
170
161
171
return m_default;
0 commit comments