From af2e22334988aebdaa3203d0f9b0b0f2f841ea9d Mon Sep 17 00:00:00 2001 From: Andriy Utkin Date: Thu, 4 Jul 2024 00:19:04 +0100 Subject: [PATCH] ConsumerThread: parametrize thread name --- lib/MySQL_Monitor.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/MySQL_Monitor.cpp b/lib/MySQL_Monitor.cpp index fd35843bf..10f1d97fe 100644 --- a/lib/MySQL_Monitor.cpp +++ b/lib/MySQL_Monitor.cpp @@ -63,13 +63,17 @@ template class ConsumerThread : public Thread { wqueue*>& m_queue; int thrn; + char thr_name[16]; public: - ConsumerThread(wqueue*>& queue, int _n) : m_queue(queue) { + ConsumerThread(wqueue*>& queue, int _n, char thread_name[16]=NULL) : m_queue(queue) { thrn=_n; + if (thread_name && thread_name[0]) { + snprintf(thr_name, sizeof(thr_name), "%.16s", thread_name); + } else { + snprintf(thr_name, sizeof(thr_name), "%.12s%03d", typeid(T).name(), thrn); + } } void* run() { - char thr_name[16]; - snprintf(thr_name, sizeof(thr_name), "%.12s%03d", typeid(T).name(), thrn); set_thread_name(thr_name); // Remove 1 item at a time and process it. Blocks if no items are // available to process. @@ -4994,7 +4998,7 @@ __monitor_run: } ConsumerThread **threads= (ConsumerThread **)malloc(sizeof(ConsumerThread *)*num_threads); for (unsigned int i=0;i(*queue, 0); + threads[i] = new ConsumerThread(*queue, 0, "MyMonStateData"); threads[i]->start(2048,false); } started_threads += num_threads; @@ -5064,7 +5068,7 @@ __monitor_run: threads= (ConsumerThread **)realloc(threads, sizeof(ConsumerThread *)*num_threads); started_threads += (num_threads - old_num_threads); for (unsigned int i = old_num_threads ; i < num_threads ; i++) { - threads[i] = new ConsumerThread(*queue, 0); + threads[i] = new ConsumerThread(*queue, 0, "MyMonStateData"); threads[i]->start(2048,false); } } @@ -5093,7 +5097,7 @@ __monitor_run: threads= (ConsumerThread **)realloc(threads, sizeof(ConsumerThread *)*num_threads); started_threads += new_threads; for (unsigned int i = old_num_threads ; i < num_threads ; i++) { - threads[i] = new ConsumerThread(*queue, 0); + threads[i] = new ConsumerThread(*queue, 0, "MyMonStateData"); threads[i]->start(2048,false); } } @@ -5113,7 +5117,7 @@ __monitor_run: aux_threads = qsize; started_threads += aux_threads; for (unsigned int i=0; i(*queue, 245); + threads_aux[i] = new ConsumerThread(*queue, 245, "MyMonStateData"); threads_aux[i]->start(2048,false); } for (unsigned int i=0; i