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

Function produce_func

test/bthread_cond_bug_unittest.cpp:69–98  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

67}
68
69void* produce_func(void* arg) {
70 const int64_t wait_us = FLAGS_wait_us;
71 LOG(INFO) << "wait us:" << wait_us;
72 int64_t idx = (int64_t)(arg);
73 int32_t i = 0;
74 while (!bthread_stopped(bthread_self())) {
75 //LOG(INFO) << "come to a new round " << idx << "round[" << i << "]";
76 {
77 Lock lock(g_mutex);
78 while (g_que.size() >= g_capacity && !bthread_stopped(bthread_self())) {
79 g_stat[idx].wait_count << 1;
80 //LOG(INFO) << "wait begin " << idx;
81 int ret = g_cond.wait_for(lock, wait_us);
82 if (ret == ETIMEDOUT) {
83 g_stat[idx].wait_timeout_count << 1;
84 //LOG_EVERY_SECOND(INFO) << "wait timeout " << idx;
85 } else {
86 g_stat[idx].wait_success_count << 1;
87 //LOG_EVERY_SECOND(INFO) << "wait early " << idx;
88 }
89 }
90 g_que.push_back(++i);
91 //LOG(INFO) << "push back " << idx << " data[" << i << "]";
92 }
93 usleep(rand() % 20 + 5);
94 g_stat[idx].loop_count.fetch_add(1);
95 }
96 LOG(INFO) << "producer func return, idx:" << idx;
97 return nullptr;
98}
99
100void* consume_func(void* arg) {
101 while (!bthread_stopped(bthread_self())) {

Callers

nothing calls this directly

Calls 6

bthread_stoppedFunction · 0.85
bthread_selfFunction · 0.85
wait_forMethod · 0.80
fetch_addMethod · 0.80
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected