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

Function TEST

test/bthread_once_unittest.cpp:56–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54}
55
56TEST(BthreadOnceTest, once) {
57 bthread_t bid;
58 ASSERT_EQ(0, bthread_start_background(
59 &bid, NULL, first_bthread_once_task, NULL));
60 while (!g_bthread_once_started) {
61 bthread_usleep(1000);
62 }
63 ASSERT_NE(nullptr, bthread::g_task_control);
64 int concurrency = bthread::g_task_control->concurrency();
65 LOG(INFO) << "concurrency: " << concurrency;
66 ASSERT_GT(concurrency, 0);
67 std::vector<bthread_t> bids(concurrency * 100);
68 for (auto& id : bids) {
69 ASSERT_EQ(0, bthread_start_background(
70 &id, NULL, other_bthread_once_task, NULL));
71 }
72 bthread_once_task();
73
74 for (auto& id : bids) {
75 bthread_join(id, NULL);
76 }
77 bthread_join(bid, NULL);
78}
79
80bool g_bthread_started = false;
81butil::atomic<int> g_bthread_singleton_count(0);

Callers

nothing calls this directly

Calls 6

bthread_start_backgroundFunction · 0.85
bthread_usleepFunction · 0.85
bthread_once_taskFunction · 0.85
bthread_joinFunction · 0.85
get_bthread_singletonFunction · 0.85
concurrencyMethod · 0.80

Tested by

no test coverage detected