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

Function ping_pong_thread

test/bthread_cond_unittest.cpp:292–309  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

290};
291
292void *ping_pong_thread(void* arg) {
293 PingPongArg* a = (PingPongArg*)arg;
294 long local_count = 0;
295 bool odd = (a->nthread.fetch_add(1)) % 2;
296 int old_signal = 0;
297 while (!a->stopped) {
298 if (odd) {
299 a->sig1.notify();
300 old_signal = a->sig2.wait(old_signal);
301 } else {
302 old_signal = a->sig1.wait(old_signal);
303 a->sig2.notify();
304 }
305 ++local_count;
306 }
307 a->total_count.fetch_add(local_count);
308 return NULL;
309}
310
311TEST(CondTest, ping_pong) {
312 PingPongArg arg;

Callers

nothing calls this directly

Calls 3

fetch_addMethod · 0.80
notifyMethod · 0.45
waitMethod · 0.45

Tested by

no test coverage detected