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,7 +130,7 @@ void MainApp::start() | ||
| 130 | { | 130 | { |
| 131 | std::shared_ptr<ThreadData> t(new ThreadData(i, subscriptionStore)); | 131 | std::shared_ptr<ThreadData> t(new ThreadData(i, subscriptionStore)); |
| 132 | std::thread thread(do_thread_work, t.get()); | 132 | std::thread thread(do_thread_work, t.get()); |
| 133 | - t->thread = std::move(thread); | 133 | + t->moveThreadHere(std::move(thread)); |
| 134 | threads.push_back(t); | 134 | threads.push_back(t); |
| 135 | } | 135 | } |
| 136 | 136 |
threaddata.cpp
| 1 | #include "threaddata.h" | 1 | #include "threaddata.h" |
| 2 | +#include <string> | ||
| 3 | +#include <sstream> | ||
| 2 | 4 | ||
| 3 | ThreadData::ThreadData(int threadnr, std::shared_ptr<SubscriptionStore> &subscriptionStore) : | 5 | ThreadData::ThreadData(int threadnr, std::shared_ptr<SubscriptionStore> &subscriptionStore) : |
| 4 | subscriptionStore(subscriptionStore), | 6 | subscriptionStore(subscriptionStore), |
| @@ -14,6 +16,17 @@ ThreadData::ThreadData(int threadnr, std::shared_ptr<SubscriptionStore> &subscri | @@ -14,6 +16,17 @@ ThreadData::ThreadData(int threadnr, std::shared_ptr<SubscriptionStore> &subscri | ||
| 14 | check<std::runtime_error>(epoll_ctl(epollfd, EPOLL_CTL_ADD, event_fd, &ev)); | 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 | void ThreadData::quit() | 30 | void ThreadData::quit() |
| 18 | { | 31 | { |
| 19 | running = false; | 32 | running = false; |
threaddata.h
| @@ -36,6 +36,7 @@ public: | @@ -36,6 +36,7 @@ public: | ||
| 36 | 36 | ||
| 37 | ThreadData(int threadnr, std::shared_ptr<SubscriptionStore> &subscriptionStore); | 37 | ThreadData(int threadnr, std::shared_ptr<SubscriptionStore> &subscriptionStore); |
| 38 | 38 | ||
| 39 | + void moveThreadHere(std::thread &&thread); | ||
| 39 | void quit(); | 40 | void quit(); |
| 40 | void giveClient(Client_p client); | 41 | void giveClient(Client_p client); |
| 41 | Client_p getClient(int fd); | 42 | Client_p getClient(int fd); |