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

Method worker_thread

src/bthread/task_control.cpp:89–137  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87};
88
89void* TaskControl::worker_thread(void* arg) {
90 run_worker_startfn();
91#ifdef BAIDU_INTERNAL
92 logging::ComlogInitializer comlog_initializer;
93#endif
94
95 auto dummy = static_cast<WorkerThreadArgs*>(arg);
96 auto c = dummy->c;
97 auto tag = dummy->tag;
98 delete dummy;
99 run_tagged_worker_startfn(tag);
100
101 TaskGroup* g = c->create_group(tag);
102 TaskStatistics stat;
103 if (NULL == g) {
104 LOG(ERROR) << "Fail to create TaskGroup in pthread=" << pthread_self();
105 return NULL;
106 }
107
108 g->_tid = pthread_self();
109
110 int worker_id = c->_next_worker_id.fetch_add(
111 1, butil::memory_order_relaxed);
112 if (!c->_cpus.empty()) {
113 bind_thread_to_cpu(pthread_self(), c->_cpus[worker_id % c->_cpus.size()]);
114 }
115 if (FLAGS_task_group_set_worker_name) {
116 std::string worker_thread_name = butil::string_printf(
117 "brpc_wkr:%d-%d", g->tag(), worker_id);
118 butil::PlatformThread::SetNameSimple(worker_thread_name.c_str());
119 }
120 BT_VLOG << "Created worker=" << pthread_self() << " tid=" << g->_tid
121 << " bthread=" << g->main_tid() << " tag=" << g->tag();
122 tls_task_group = g;
123 c->_nworkers << 1;
124 c->tag_nworkers(g->tag()) << 1;
125
126 g->run_main_task();
127
128 stat = g->main_stat();
129 BT_VLOG << "Destroying worker=" << pthread_self() << " bthread="
130 << g->main_tid() << " idle=" << stat.cputime_ns / 1000000.0
131 << "ms uptime=" << g->current_uptime_ns() / 1000000.0 << "ms";
132 tls_task_group = NULL;
133 g->destroy_self();
134 c->_nworkers << -1;
135 c->tag_nworkers(g->tag()) << -1;
136 return NULL;
137}
138
139TaskGroup* TaskControl::create_group(bthread_tag_t tag) {
140 TaskGroup* g = new (std::nothrow) TaskGroup(this);

Callers

nothing calls this directly

Calls 14

run_worker_startfnFunction · 0.85
string_printfFunction · 0.85
create_groupMethod · 0.80
fetch_addMethod · 0.80
tagMethod · 0.80
main_tidMethod · 0.80
run_main_taskMethod · 0.80
main_statMethod · 0.80
current_uptime_nsMethod · 0.80
destroy_selfMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected