| 1268 | } |
| 1269 | |
| 1270 | void application_impl::set_client(const client_t& _client) { |
| 1271 | client_ = _client; |
| 1272 | |
| 1273 | // it is through `set_client` that the routing host assign a client-id via ASSIGN_CLIENT_ACK_ID |
| 1274 | // unfortunately, threads often (but not always, it is racy!) start before this point, and use |
| 1275 | // the default client-id (0xffff) for the thread names |
| 1276 | |
| 1277 | // therefore re-assign all of the thread names. It also helps in case of a client-id |
| 1278 | // re-assignment |
| 1279 | |
| 1280 | #if defined(__linux__) || defined(__QNX__) |
| 1281 | // start thread |
| 1282 | if (start_thread_ != 0) { |
| 1283 | std::stringstream s; |
| 1284 | s << hex4(client_) << "_io" << std::setw(2) << 0; |
| 1285 | pthread_setname_np(start_thread_, s.str().c_str()); |
| 1286 | } |
| 1287 | // io thread(s) |
| 1288 | { |
| 1289 | std::scoped_lock its_lock{start_stop_mutex_}; |
| 1290 | for (size_t i = 0; i < io_threads_.size(); ++i) { |
| 1291 | std::stringstream s; |
| 1292 | s << hex4(client_) << "_io" << std::setw(2) << i + 1; |
| 1293 | |
| 1294 | pthread_setname_np(io_threads_[i]->native_handle(), s.str().c_str()); |
| 1295 | } |
| 1296 | } |
| 1297 | // dispatch thread(s) |
| 1298 | { |
| 1299 | std::scoped_lock its_lock{handlers_mutex_}; |
| 1300 | |
| 1301 | // cannot distinguish main vs secondary dispatchers, so name them all equally |
| 1302 | // they are not numbered anyhow, and secondary dispatchers are temporary - there is likely |
| 1303 | // none at all |
| 1304 | std::stringstream s; |
| 1305 | s << hex4(client_) << "_m_dispatch"; |
| 1306 | |
| 1307 | for (const auto& [id, thread] : dispatchers_) { |
| 1308 | pthread_setname_np(thread->native_handle(), s.str().c_str()); |
| 1309 | } |
| 1310 | } |
| 1311 | // stop thread |
| 1312 | { |
| 1313 | std::scoped_lock its_lock{start_stop_mutex_}; |
| 1314 | |
| 1315 | std::stringstream s; |
| 1316 | s << hex4(client_) << "_shutdown"; |
| 1317 | |
| 1318 | if (stop_thread_.joinable()) { |
| 1319 | pthread_setname_np(stop_thread_.native_handle(), s.str().c_str()); |
| 1320 | } |
| 1321 | } |
| 1322 | #endif |
| 1323 | } |
| 1324 | |
| 1325 | session_t application_impl::get_session(bool _is_request) { |
| 1326 | |