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

Function TEST

test/bthread_futex_unittest.cpp:66–105  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

64}
65
66TEST(FutexTest, rdlock_performance) {
67 const size_t N = 100000;
68 butil::atomic<int> lock1(0);
69 pthread_t rth[8];
70 for (size_t i = 0; i < ARRAY_SIZE(rth); ++i) {
71 ASSERT_EQ(0, pthread_create(&rth[i], NULL, read_thread, &lock1));
72 }
73
74 const int64_t t1 = butil::cpuwide_time_ns();
75 for (size_t i = 0; i < N; ++i) {
76 if (nthread) {
77 lock1.fetch_add(1);
78 bthread::futex_wake_private(&lock1, 1);
79 } else {
80 lock1.fetch_add(1);
81 if (nthread) {
82 bthread::futex_wake_private(&lock1, 1);
83 }
84 }
85 }
86 const int64_t t2 = butil::cpuwide_time_ns();
87
88 bthread_usleep(3000000);
89 stop = true;
90 for (int i = 0; i < 10; ++i) {
91 bthread::futex_wake_private(&lock1, INT_MAX);
92 sched_yield();
93 }
94
95 int njob = 0;
96 int* res;
97 for (size_t i = 0; i < ARRAY_SIZE(rth); ++i) {
98 pthread_join(rth[i], (void**)&res);
99 njob += *res;
100 delete res;
101 }
102 printf("wake %lu times, %" PRId64 "ns each, lock1=%d njob=%d\n",
103 N, (t2-t1)/N, lock1.load(), njob);
104 ASSERT_EQ(N, (size_t)(lock1.load() + njob));
105}
106
107TEST(FutexTest, futex_wake_before_wait) {
108 int lock1 = 0;

Callers

nothing calls this directly

Calls 9

cpuwide_time_nsFunction · 0.85
bthread_usleepFunction · 0.85
fetch_addMethod · 0.80
n_elapsedMethod · 0.80
futex_wake_privateFunction · 0.50
futex_wait_privateFunction · 0.50
loadMethod · 0.45
startMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected