| 67 | } |
| 68 | |
| 69 | void* 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 | |
| 100 | void* consume_func(void* arg) { |
| 101 | while (!bthread_stopped(bthread_self())) { |
nothing calls this directly
no test coverage detected