Skip to content

Commit 1152b80

Browse files
authored
Use SetNameSimple instead of SetName to avoid deadlock (#3127)
1 parent 0141e9e commit 1152b80

11 files changed

Lines changed: 23 additions & 8 deletions

src/brpc/details/usercode_backup_pool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ UserCodeBackupPool::UserCodeBackupPool()
9292
}
9393

9494
static void* UserCodeRunner(void* args) {
95-
butil::PlatformThread::SetName("brpc_user_code_runner");
95+
butil::PlatformThread::SetNameSimple("brpc_user_code_runner");
9696
static_cast<UserCodeBackupPool*>(args)->UserCodeRunningLoop();
9797
return NULL;
9898
}

src/bthread/execution_queue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ void* ExecutionQueueBase::_execute_tasks(void* arg) {
208208
}
209209

210210
void* ExecutionQueueBase::_execute_tasks_pthread(void* arg) {
211-
butil::PlatformThread::SetName("ExecutionQueue");
211+
butil::PlatformThread::SetNameSimple("ExecutionQueue");
212212
auto head = (TaskNode*)arg;
213213
auto m = (ExecutionQueueBase*)head->q;
214214
m->_current_head = head;

src/bthread/task_control.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void* TaskControl::worker_thread(void* arg) {
103103
std::string worker_thread_name = butil::string_printf(
104104
"brpc_wkr:%d-%d", g->tag(),
105105
c->_next_worker_id.fetch_add(1, butil::memory_order_relaxed));
106-
butil::PlatformThread::SetName(worker_thread_name.c_str());
106+
butil::PlatformThread::SetNameSimple(worker_thread_name.c_str());
107107
}
108108
BT_VLOG << "Created worker=" << pthread_self() << " tid=" << g->_tid
109109
<< " bthread=" << g->main_tid() << " tag=" << g->tag();

src/bthread/timer_thread.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ inline bool task_greater(const TimerThread::Task* a, const TimerThread::Task* b)
121121
}
122122

123123
void* TimerThread::run_this(void* arg) {
124-
butil::PlatformThread::SetName("brpc_timer");
124+
butil::PlatformThread::SetNameSimple("brpc_timer");
125125
static_cast<TimerThread*>(arg)->run();
126126
return NULL;
127127
}

src/butil/threading/platform_thread.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ class BUTIL_EXPORT PlatformThread {
154154
// otherwise. This name pointer is not copied internally. Thus, it must stay
155155
// valid until the thread ends.
156156
static void SetName(const char* name);
157+
static void SetNameSimple(const char* name);
157158

158159
// Gets the thread name, if previously set by SetName.
159160
static const char* GetName();

src/butil/threading/platform_thread_freebsd.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ void PlatformThread::SetName(const char* name) {
4848
ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name);
4949
tracked_objects::ThreadData::InitializeThreadContext(name);
5050

51+
SetNameSimple(name);
52+
}
53+
54+
// static
55+
void PlatformThread::SetNameSimple(const char* name) {
5156
#if !defined(OS_NACL)
5257
// On FreeBSD we can get the thread names to show up in the debugger by
5358
// setting the process name for the LWP. We don't want to do this for the

src/butil/threading/platform_thread_linux.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ int ThreadNiceValue(ThreadPriority priority) {
5454
void PlatformThread::SetName(const char* name) {
5555
ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name);
5656

57+
SetNameSimple(name);
58+
}
59+
// static
60+
void PlatformThread::SetNameSimple(const char* name) {
5761
#if !defined(OS_NACL)
5862
// On linux we can get the thread names to show up in the debugger by setting
5963
// the process name for the LWP. We don't want to do this for the main

src/butil/threading/platform_thread_mac.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ void InitThreading() {
4646
// TODO: add tracked_objects related headers
4747
//tracked_objects::ThreadData::InitializeThreadContext(name);
4848

49+
SetNameSimple(name);
50+
}
51+
52+
// static
53+
void PlatformThread::SetNameSimple(const char* name) {
4954
// Mac OS X does not expose the length limit of the name, so
5055
// hardcode it.
5156
const int kMaxNameLength = 63;

src/bvar/collector.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ class Collector : public bvar::Reducer<Collected*, CombineCollected> {
7777
int64_t interval_us);
7878

7979
static void* run_grab_thread(void* arg) {
80-
butil::PlatformThread::SetName("bvar_collector_grabber");
80+
butil::PlatformThread::SetNameSimple("bvar_collector_grabber");
8181
static_cast<Collector*>(arg)->grab_thread();
8282
return NULL;
8383
}
8484

8585
static void* run_dump_thread(void* arg) {
86-
butil::PlatformThread::SetName("bvar_collector_dumper");
86+
butil::PlatformThread::SetNameSimple("bvar_collector_dumper");
8787
static_cast<Collector*>(arg)->dump_thread();
8888
return NULL;
8989
}

src/bvar/detail/sampler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class SamplerCollector : public bvar::Reducer<Sampler*, CombineSampler> {
109109
void run();
110110

111111
static void* sampling_thread(void* arg) {
112-
butil::PlatformThread::SetName("bvar_sampler");
112+
butil::PlatformThread::SetNameSimple("bvar_sampler");
113113
static_cast<SamplerCollector*>(arg)->run();
114114
return NULL;
115115
}

0 commit comments

Comments
 (0)