Skip to content

Commit

Permalink
ConsumerThread: parametrize thread name
Browse files Browse the repository at this point in the history
  • Loading branch information
Andriy Utkin committed Jul 3, 2024
1 parent 474d662 commit af2e223
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/MySQL_Monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,17 @@ template<typename T, bool check_monitor_enabled_flag = true>
class ConsumerThread : public Thread {
wqueue<WorkItem<T>*>& m_queue;
int thrn;
char thr_name[16];
public:
ConsumerThread(wqueue<WorkItem<T>*>& queue, int _n) : m_queue(queue) {
ConsumerThread(wqueue<WorkItem<T>*>& 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.
Expand Down Expand Up @@ -4994,7 +4998,7 @@ void * MySQL_Monitor::run() {
}
ConsumerThread<MySQL_Monitor_State_Data> **threads= (ConsumerThread<MySQL_Monitor_State_Data> **)malloc(sizeof(ConsumerThread<MySQL_Monitor_State_Data> *)*num_threads);
for (unsigned int i=0;i<num_threads; i++) {
threads[i] = new ConsumerThread<MySQL_Monitor_State_Data>(*queue, 0);
threads[i] = new ConsumerThread<MySQL_Monitor_State_Data>(*queue, 0, "MyMonStateData");
threads[i]->start(2048,false);
}
started_threads += num_threads;
Expand Down Expand Up @@ -5064,7 +5068,7 @@ void * MySQL_Monitor::run() {
threads= (ConsumerThread<MySQL_Monitor_State_Data> **)realloc(threads, sizeof(ConsumerThread<MySQL_Monitor_State_Data> *)*num_threads);
started_threads += (num_threads - old_num_threads);
for (unsigned int i = old_num_threads ; i < num_threads ; i++) {
threads[i] = new ConsumerThread<MySQL_Monitor_State_Data>(*queue, 0);
threads[i] = new ConsumerThread<MySQL_Monitor_State_Data>(*queue, 0, "MyMonStateData");
threads[i]->start(2048,false);
}
}
Expand Down Expand Up @@ -5093,7 +5097,7 @@ void * MySQL_Monitor::run() {
threads= (ConsumerThread<MySQL_Monitor_State_Data> **)realloc(threads, sizeof(ConsumerThread<MySQL_Monitor_State_Data> *)*num_threads);
started_threads += new_threads;
for (unsigned int i = old_num_threads ; i < num_threads ; i++) {
threads[i] = new ConsumerThread<MySQL_Monitor_State_Data>(*queue, 0);
threads[i] = new ConsumerThread<MySQL_Monitor_State_Data>(*queue, 0, "MyMonStateData");
threads[i]->start(2048,false);
}
}
Expand All @@ -5113,7 +5117,7 @@ void * MySQL_Monitor::run() {
aux_threads = qsize;
started_threads += aux_threads;
for (unsigned int i=0; i<qsize; i++) {
threads_aux[i] = new ConsumerThread<MySQL_Monitor_State_Data>(*queue, 245);
threads_aux[i] = new ConsumerThread<MySQL_Monitor_State_Data>(*queue, 245, "MyMonStateData");
threads_aux[i]->start(2048,false);
}
for (unsigned int i=0; i<qsize; i++) {
Expand Down

0 comments on commit af2e223

Please sign in to comment.