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

Function worker1_impl

test/bthread_key_unittest.cpp:89–116  ·  view source on GitHub ↗

NOTE: returns void to use ASSERT

Source from the content-addressed store, hash-verified

87
88// NOTE: returns void to use ASSERT
89static void worker1_impl(Counters* cs) {
90 cs->nenterthread.fetch_add(1, butil::memory_order_relaxed);
91 bthread_key_t k[NKEY_PER_WORKER];
92 CountersWrapper* ws[arraysize(k)];
93 for (size_t i = 0; i < arraysize(k); ++i) {
94 ASSERT_EQ(0, bthread_key_create(&k[i], destroy_counters_wrapper));
95 }
96 for (size_t i = 0; i < arraysize(k); ++i) {
97 ws[i] = new CountersWrapper(cs, k[i]);
98 }
99 // Get just-created tls should return NULL.
100 for (size_t i = 0; i < arraysize(k); ++i) {
101 ASSERT_EQ(NULL, bthread_getspecific(k[i]));
102 }
103 for (size_t i = 0; i < arraysize(k); ++i) {
104 cs->ncreate.fetch_add(1, butil::memory_order_relaxed);
105 ASSERT_EQ(0, bthread_setspecific(k[i], ws[i]))
106 << "i=" << i << " is_bthread=" << !!bthread_self();
107
108 }
109 // Sleep a while to make some context switches. TLS should be unchanged.
110 bthread_usleep(10000);
111
112 for (size_t i = 0; i < arraysize(k); ++i) {
113 ASSERT_EQ(ws[i], bthread_getspecific(k[i])) << "i=" << i;
114 }
115 cs->nleavethread.fetch_add(1, butil::memory_order_relaxed);
116}
117
118static void* worker1(void* arg) {
119 worker1_impl(static_cast<Counters*>(arg));

Callers 1

worker1Function · 0.85

Calls 6

bthread_key_createFunction · 0.85
bthread_getspecificFunction · 0.85
bthread_setspecificFunction · 0.85
bthread_selfFunction · 0.85
bthread_usleepFunction · 0.85
fetch_addMethod · 0.80

Tested by

no test coverage detected