mirror of
https://github.com/MariaDB/server.git
synced 2025-01-15 19:42:28 +01:00
MDEV-31095 tpool - do not create new worker, if thread creation is pending.
Use an std::atomic_flag to track thread creation in progress. This is mainly a cleanup, the effect of this change was not measureable in my tests.
This commit is contained in:
parent
e33e2fa949
commit
9e62ab7aaf
1 changed files with 5 additions and 1 deletions
|
@ -278,6 +278,7 @@ class thread_pool_generic : public thread_pool
|
|||
/* maintenance related statistics (see maintenance()) */
|
||||
size_t m_last_thread_count;
|
||||
unsigned long long m_last_activity;
|
||||
std::atomic_flag m_thread_creation_pending= ATOMIC_FLAG_INIT;
|
||||
|
||||
void worker_main(worker_data *thread_data);
|
||||
void worker_end(worker_data* thread_data);
|
||||
|
@ -575,6 +576,7 @@ void thread_pool_generic::worker_main(worker_data *thread_var)
|
|||
m_worker_init_callback();
|
||||
|
||||
tls_worker_data = thread_var;
|
||||
m_thread_creation_pending.clear();
|
||||
|
||||
while (get_task(thread_var, &task) && task)
|
||||
{
|
||||
|
@ -720,11 +722,13 @@ static int throttling_interval_ms(size_t n_threads,size_t concurrency)
|
|||
/* Create a new worker.*/
|
||||
bool thread_pool_generic::add_thread()
|
||||
{
|
||||
if (m_thread_creation_pending.test_and_set())
|
||||
return false;
|
||||
|
||||
size_t n_threads = thread_count();
|
||||
|
||||
if (n_threads >= m_max_threads)
|
||||
return false;
|
||||
|
||||
if (n_threads >= m_min_threads)
|
||||
{
|
||||
auto now = std::chrono::system_clock::now();
|
||||
|
|
Loading…
Reference in a new issue