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

Function batch_waker

test/bthread_futex_unittest.cpp:167–190  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

165}
166
167void* batch_waker(void* lock) {
168 bthread_usleep(10000);
169 const size_t REP = 100000;
170 int nwakeup = 0;
171 butil::Timer tm;
172 tm.start();
173 for (size_t i = 0; i < REP; ++i) {
174 if (nevent.fetch_add(1, butil::memory_order_relaxed) == 0) {
175 nwakeup += bthread::futex_wake_private(lock, 1);
176 int expected = 1;
177 while (1) {
178 int last_expected = expected;
179 if (nevent.compare_exchange_strong(expected, 0, butil::memory_order_relaxed)) {
180 break;
181 }
182 nwakeup += bthread::futex_wake_private(lock, expected - last_expected);
183 }
184 }
185 }
186 tm.stop();
187 EXPECT_EQ(0, nwakeup);
188 printf("futex_wake nop = %" PRId64 "ns\n", tm.n_elapsed() / REP);
189 return NULL;
190}
191
192TEST(FutexTest, many_futex_wake_nop_perf) {
193 pthread_t th[8];

Callers

nothing calls this directly

Calls 7

bthread_usleepFunction · 0.85
fetch_addMethod · 0.80
n_elapsedMethod · 0.80
futex_wake_privateFunction · 0.50
startMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected