Commit 3f88166320c8411489418ba83a06a39c7096ab13
1 parent
163d14e8
Custom thread names
Showing
3 changed files
with
15 additions
and
1 deletions
mainapp.cpp
| ... | ... | @@ -130,7 +130,7 @@ void MainApp::start() |
| 130 | 130 | { |
| 131 | 131 | std::shared_ptr<ThreadData> t(new ThreadData(i, subscriptionStore)); |
| 132 | 132 | std::thread thread(do_thread_work, t.get()); |
| 133 | - t->thread = std::move(thread); | |
| 133 | + t->moveThreadHere(std::move(thread)); | |
| 134 | 134 | threads.push_back(t); |
| 135 | 135 | } |
| 136 | 136 | ... | ... |
threaddata.cpp
| 1 | 1 | #include "threaddata.h" |
| 2 | +#include <string> | |
| 3 | +#include <sstream> | |
| 2 | 4 | |
| 3 | 5 | ThreadData::ThreadData(int threadnr, std::shared_ptr<SubscriptionStore> &subscriptionStore) : |
| 4 | 6 | subscriptionStore(subscriptionStore), |
| ... | ... | @@ -14,6 +16,17 @@ ThreadData::ThreadData(int threadnr, std::shared_ptr<SubscriptionStore> &subscri |
| 14 | 16 | check<std::runtime_error>(epoll_ctl(epollfd, EPOLL_CTL_ADD, event_fd, &ev)); |
| 15 | 17 | } |
| 16 | 18 | |
| 19 | +void ThreadData::moveThreadHere(std::thread &&thread) | |
| 20 | +{ | |
| 21 | + this->thread = std::move(thread); | |
| 22 | + | |
| 23 | + pthread_t native = this->thread.native_handle(); | |
| 24 | + std::ostringstream threadName; | |
| 25 | + threadName << "FlashMQ T " << threadnr; | |
| 26 | + threadName.flush(); | |
| 27 | + pthread_setname_np(native, threadName.str().c_str()); | |
| 28 | +} | |
| 29 | + | |
| 17 | 30 | void ThreadData::quit() |
| 18 | 31 | { |
| 19 | 32 | running = false; | ... | ... |
threaddata.h