Skip to content

Commit

Permalink
num_worker_threads my_atomic to Atomic_counter
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Vojtovich committed Mar 27, 2020
1 parent e91a3ea commit 9eae063
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
12 changes: 11 additions & 1 deletion sql/mysqld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7623,6 +7623,16 @@ int show_threadpool_idle_threads(THD *thd, SHOW_VAR *var, char *buff,
*(int *)buff= tp_get_idle_thread_count();
return 0;
}


static int show_threadpool_threads(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{
var->type= SHOW_INT;
var->value= buff;
*(reinterpret_cast<int*>(buff))= tp_get_thread_count();
return 0;
}
#endif

/*
Expand Down Expand Up @@ -7842,7 +7852,7 @@ SHOW_VAR status_vars[]= {
#endif
#ifdef HAVE_POOL_OF_THREADS
{"Threadpool_idle_threads", (char *) &show_threadpool_idle_threads, SHOW_SIMPLE_FUNC},
{"Threadpool_threads", (char *) &tp_stats.num_worker_threads, SHOW_INT},
{"Threadpool_threads", (char *) &show_threadpool_threads, SHOW_SIMPLE_FUNC},
#endif
{"Threads_cached", (char*) &cached_thread_count, SHOW_LONG_NOFLUSH},
{"Threads_connected", (char*) &connection_count, SHOW_INT},
Expand Down
2 changes: 1 addition & 1 deletion sql/threadpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extern void tp_timeout_handler(TP_connection *c);
struct TP_STATISTICS
{
/* Current number of worker thread. */
volatile int32 num_worker_threads;
Atomic_counter<uint32_t> num_worker_threads;
};

extern TP_STATISTICS tp_stats;
Expand Down
4 changes: 2 additions & 2 deletions sql/threadpool_generic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ static void add_thread_count(thread_group_t *thread_group, int32 count)
thread_group->thread_count += count;
/* worker starts out and end in "active" state */
thread_group->active_thread_count += count;
my_atomic_add32(&tp_stats.num_worker_threads, count);
tp_stats.num_worker_threads+= count;
}


Expand All @@ -928,7 +928,7 @@ static int create_worker(thread_group_t *thread_group)
int err;

DBUG_ENTER("create_worker");
if (tp_stats.num_worker_threads >= (int)threadpool_max_threads
if (tp_stats.num_worker_threads >= threadpool_max_threads
&& thread_group->thread_count >= 2)
{
err= 1;
Expand Down
4 changes: 2 additions & 2 deletions sql/threadpool_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ void tp_win_callback_prolog()
/* Running in new worker thread*/
FlsSetValue(fls, (void *)1);
statistic_increment(thread_created, &LOCK_status);
InterlockedIncrement((volatile long *)&tp_stats.num_worker_threads);
tp_stats.num_worker_threads++;
my_thread_init();
}
}
Expand All @@ -355,7 +355,7 @@ static VOID WINAPI thread_destructor(void *data)
{
if(data)
{
InterlockedDecrement((volatile long *)&tp_stats.num_worker_threads);
tp_stats.num_worker_threads--;
my_thread_end();
}
}
Expand Down

0 comments on commit 9eae063

Please sign in to comment.