Skip to content

Commit a864fbe

Browse files
ricardolleiteduartenfonseca
authored andcommitted
rm: fix client registration thread names
Summary 0c4b756 introduced several client registration threads, and assigned especially long thread names. This is problematic, because in Linux, pthread_setname_np silently fails if the thread name is longer than 16 characters
1 parent a72cbea commit a864fbe

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

implementation/routing/src/routing_manager_stub.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,16 @@ void routing_manager_stub::start() {
135135
{
136136
std::scoped_lock its_thread_pool_lock(client_registration_thread_pool_mutex_);
137137
for (size_t i = 0; i < VSOMEIP_DEFAULT_REGISTER_THREAD_COUNT; i++) {
138-
auto its_thread = std::make_shared<std::thread>(
139-
std::bind(&routing_manager_stub::client_registration_func, this));
138+
auto its_thread = std::make_shared<std::thread>([this, i]() {
139+
#if defined(__linux__) || defined(ANDROID)
140+
std::stringstream s;
141+
s << std::hex << std::setfill('0') << std::setw(4) << host_->get_client() << "_reg_"
142+
<< std::setw(2) << i;
143+
pthread_setname_np(pthread_self(), s.str().c_str());
144+
#endif
145+
client_registration_func();
146+
});
147+
140148
client_registration_thread_pool_[its_thread->get_id()] = its_thread;
141149
}
142150
}
@@ -999,14 +1007,6 @@ void routing_manager_stub::on_offered_service_request(client_t _client,
9991007
}
10001008

10011009
void routing_manager_stub::client_registration_func(void) {
1002-
#if defined(__linux__) || defined(ANDROID)
1003-
{
1004-
std::stringstream s;
1005-
s << std::hex << std::setfill('0') << std::setw(4) << host_->get_client() << "_client_reg_"
1006-
<< std::hex << std::this_thread::get_id();
1007-
pthread_setname_np(pthread_self(), s.str().c_str());
1008-
}
1009-
#endif
10101010
std::unique_lock<std::mutex> its_lock(client_registration_mutex_);
10111011
while (client_registration_running_) {
10121012
client_registration_condition_.wait(its_lock, [this] {

0 commit comments

Comments
 (0)