MCPcopy Create free account
hub / github.com/apache/brpc / add_with_suspend

Function add_with_suspend

test/bthread_execution_queue_unittest.cpp:283–314  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

281int urgent_times = 0;
282
283int add_with_suspend(void* meta, bthread::TaskIterator<LongIntTask>& iter) {
284 int64_t* result = (int64_t*)meta;
285 if (iter.is_queue_stopped()) {
286 stopped = true;
287 return 0;
288 }
289 if (g_should_be_urgent) {
290 g_should_be_urgent = false;
291 EXPECT_EQ(-1, iter->value) << urgent_times;
292 if (iter->event) { iter->event->signal(); }
293 ++iter;
294 EXPECT_FALSE(iter) << urgent_times;
295 ++urgent_times;
296 } else {
297 for (; iter; ++iter) {
298 if (iter->value == -100) {
299 g_suspending = true;
300 while (g_suspending) {
301 bthread_usleep(100);
302 }
303 g_should_be_urgent = true;
304 if (iter->event) { iter->event->signal(); }
305 EXPECT_FALSE(++iter);
306 return 0;
307 } else {
308 *result += iter->value;
309 if (iter->event) { iter->event->signal(); }
310 }
311 }
312 }
313 return 0;
314}
315
316void test_execute_urgent(bool use_pthread) {
317 g_should_be_urgent = false;

Callers

nothing calls this directly

Calls 3

bthread_usleepFunction · 0.85
is_queue_stoppedMethod · 0.80
signalMethod · 0.80

Tested by

no test coverage detected