diff options
author | Sergei Golubchik <serg@mariadb.org> | 2016-05-14 13:22:47 +0200 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2016-06-04 09:06:00 +0200 |
commit | 562c1df7d97cb23145e09b3482fd18d49476752d (patch) | |
tree | 0d8e3d45c78dafd5854e8c6d6488b232f3f631a7 /sql | |
parent | 7425610c81ca1329d72a97f57770e5b052d08079 (diff) | |
download | mariadb-git-562c1df7d97cb23145e09b3482fd18d49476752d.tar.gz |
cleanup: thread_count
move thread_count handling into THD:
* increment thread_count in THD constructor
* decrement thread_count in THD destructor
* never modify thread_count directly!
Diffstat (limited to 'sql')
-rw-r--r-- | sql/event_scheduler.cc | 1 | ||||
-rw-r--r-- | sql/mysqld.cc | 27 | ||||
-rw-r--r-- | sql/mysqld.h | 1 | ||||
-rw-r--r-- | sql/scheduler.cc | 1 | ||||
-rw-r--r-- | sql/sql_class.cc | 2 | ||||
-rw-r--r-- | sql/sql_class.h | 14 | ||||
-rw-r--r-- | sql/sql_connect.cc | 24 | ||||
-rw-r--r-- | sql/sql_insert.cc | 2 | ||||
-rw-r--r-- | sql/sql_parse.cc | 9 | ||||
-rw-r--r-- | sql/threadpool_common.cc | 1 | ||||
-rw-r--r-- | sql/wsrep_mysqld.cc | 2 |
11 files changed, 22 insertions, 62 deletions
diff --git a/sql/event_scheduler.cc b/sql/event_scheduler.cc index ea0163e3f78..3450e60f85c 100644 --- a/sql/event_scheduler.cc +++ b/sql/event_scheduler.cc @@ -134,7 +134,6 @@ post_init_event_thread(THD *thd) return TRUE; } - thread_safe_increment32(&thread_count); add_to_active_threads(thd); inc_thread_running(); return FALSE; diff --git a/sql/mysqld.cc b/sql/mysqld.cc index ad1c301a234..270d75976cb 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -2906,7 +2906,6 @@ void delete_running_thd(THD *thd) delete thd; dec_thread_running(); - dec_thread_count(); } /* @@ -2916,14 +2915,6 @@ void delete_running_thd(THD *thd) dec_thread_count() */ -void dec_thread_count(void) -{ - DBUG_ASSERT(thread_count > 0); - thread_safe_decrement32(&thread_count); - signal_thd_deleted(); -} - - /* Send a signal to unblock close_conneciton() / rpl_slave_init_thread() if there is no more threads running with a THD attached @@ -3116,7 +3107,6 @@ bool one_thread_per_connection_end(THD *thd, bool put_in_cache) if (!wsrep_applier && put_in_cache && cache_thread(thd)) DBUG_RETURN(0); // Thread is reused delete thd; - dec_thread_count(); } DBUG_PRINT("info", ("killing thread")); @@ -6329,7 +6319,6 @@ static void bootstrap(MYSQL_FILE *file) my_net_init(&thd->net,(st_vio*) 0, (void*) 0, MYF(0)); thd->max_client_packet_length= thd->net.max_packet; thd->security_ctx->master_access= ~(ulong)0; - thread_count++; // Safe as only one thread running in_bootstrap= TRUE; bootstrap_file=file; @@ -6418,7 +6407,6 @@ void create_thread_to_handle_connection(CONNECT *connect) /* Get thread from cache */ thread_cache.push_back(connect); wake_thread++; - thread_safe_decrement32(&thread_count); mysql_cond_signal(&COND_thread_cache); mysql_mutex_unlock(&LOCK_thread_cache); DBUG_PRINT("info",("Thread created")); @@ -6434,23 +6422,15 @@ void create_thread_to_handle_connection(CONNECT *connect) if ((error= mysql_thread_create(key_thread_one_connection, &connect->real_id, &connection_attrib, - handle_one_connection, - (void*) connect))) + handle_one_connection, (void*) connect))) { /* purecov: begin inspected */ - DBUG_PRINT("error", - ("Can't create thread to handle request (error %d)", + DBUG_PRINT("error", ("Can't create thread to handle request (error %d)", error)); - dec_connection_count(connect->scheduler); - statistic_increment(aborted_connects,&LOCK_status); - statistic_increment(connection_errors_internal, &LOCK_status); my_snprintf(error_message_buff, sizeof(error_message_buff), ER_DEFAULT(ER_CANT_CREATE_THREAD), error); - connect->close_with_error(ER_CANT_CREATE_THREAD, - error_message_buff, + connect->close_with_error(ER_CANT_CREATE_THREAD, error_message_buff, ER_OUT_OF_RESOURCES); - /* thread_count was incremented in create_new_thread() */ - dec_thread_count(); DBUG_VOID_RETURN; /* purecov: end */ } @@ -6502,7 +6482,6 @@ static void create_new_thread(CONNECT *connect) mysql_mutex_unlock(&LOCK_connection_count); - thread_safe_increment32(&thread_count); connect->thread_count_incremented= 1; /* diff --git a/sql/mysqld.h b/sql/mysqld.h index e538cbd724e..a49778db012 100644 --- a/sql/mysqld.h +++ b/sql/mysqld.h @@ -766,7 +766,6 @@ inline void dec_thread_running() } extern void set_server_version(void); -extern void dec_thread_count(void); #if defined(MYSQL_DYNAMIC_PLUGIN) && defined(_WIN32) extern "C" THD *_current_thd_noinline(); diff --git a/sql/scheduler.cc b/sql/scheduler.cc index 95702dbb4e1..de472ae2504 100644 --- a/sql/scheduler.cc +++ b/sql/scheduler.cc @@ -39,7 +39,6 @@ static bool no_threads_end(THD *thd, bool put_in_cache) { unlink_thd(thd); delete thd; - dec_thread_count(); } return 1; // Abort handle_one_connection } diff --git a/sql/sql_class.cc b/sql/sql_class.cc index c08e5030061..4b6e4bce3c0 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -1077,6 +1077,7 @@ THD::THD(my_thread_id id, bool is_wsrep_applier) save_prep_leaf_list= FALSE; /* Restore THR_THD */ set_current_thd(old_THR_THD); + inc_thread_count(); } @@ -1766,6 +1767,7 @@ THD::~THD() } update_global_memory_status(status_var.global_memory_used); set_current_thd(orig_thd == this ? 0 : orig_thd); + dec_thread_count(); DBUG_VOID_RETURN; } diff --git a/sql/sql_class.h b/sql/sql_class.h index 313400aa242..68afd9d4f73 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1906,6 +1906,20 @@ private: inline bool is_conventional() const { DBUG_ASSERT(0); return Statement::is_conventional(); } + void dec_thread_count(void) + { + DBUG_ASSERT(thread_count > 0); + thread_safe_decrement32(const_cast<int32*>(&thread_count)); + signal_thd_deleted(); + } + + + void inc_thread_count(void) + { + thread_safe_increment32(const_cast<int32*>(&thread_count)); + DBUG_ASSERT(!abort_loop); + } + public: MDL_context mdl_context; diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc index f210762db50..625f40a7ff8 100644 --- a/sql/sql_connect.cc +++ b/sql/sql_connect.cc @@ -1403,14 +1403,7 @@ void CONNECT::close_and_delete() if (vio) vio_close(vio); if (thread_count_incremented) - { - /* - Normally this is handled by THD::unlink. As we haven't yet created - a THD and put it in the thread list, we have to manage counting here. - */ - dec_thread_count(); dec_connection_count(scheduler); - } statistic_increment(connection_errors_internal, &LOCK_status); statistic_increment(aborted_connects,&LOCK_status); @@ -1434,23 +1427,8 @@ void CONNECT::close_with_error(uint sql_errno, close_connection(thd, close_error); delete thd; set_current_thd(0); - if (thread_count_incremented) - { - dec_thread_count(); - dec_connection_count(scheduler); - } - delete this; - statistic_increment(connection_errors_internal, &LOCK_status); - statistic_increment(aborted_connects,&LOCK_status); - } - else - { - /* - Out of memory; We can't generate an error, just close the connection - close_and_delete() will increment statistics. - */ - close_and_delete(); } + close_and_delete(); } diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index d9923c31468..9f63216af88 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -2073,7 +2073,6 @@ public: delayed_lock= global_system_variables.low_priority_updates ? TL_WRITE_LOW_PRIORITY : TL_WRITE; mysql_mutex_unlock(&LOCK_thread_count); - thread_safe_increment32(&thread_count); DBUG_VOID_RETURN; } ~Delayed_insert() @@ -2104,7 +2103,6 @@ public: my_free(thd.query()); thd.security_ctx->user= 0; thd.security_ctx->host= 0; - dec_thread_count(); } /* The following is for checking when we can delete ourselves */ diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 7dc0ef42b71..a1883d2fc21 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1076,16 +1076,11 @@ void do_handle_bootstrap(THD *thd) handle_bootstrap_impl(thd); end: + in_bootstrap= FALSE; delete thd; #ifndef EMBEDDED_LIBRARY - DBUG_ASSERT(thread_count == 1); - in_bootstrap= FALSE; - /* - dec_thread_count will signal bootstrap() function that we have ended as - thread_count will become 0. - */ - dec_thread_count(); + DBUG_ASSERT(thread_count == 0); my_thread_end(); pthread_exit(0); #endif diff --git a/sql/threadpool_common.cc b/sql/threadpool_common.cc index 9de168c9fdf..a7996efc382 100644 --- a/sql/threadpool_common.cc +++ b/sql/threadpool_common.cc @@ -201,7 +201,6 @@ void threadpool_remove_connection(THD *thd) close_connection(thd, 0); unlink_thd(thd); delete thd; - dec_thread_count(); /* Free resources associated with this connection: diff --git a/sql/wsrep_mysqld.cc b/sql/wsrep_mysqld.cc index 531b624fad1..d76f18a52bb 100644 --- a/sql/wsrep_mysqld.cc +++ b/sql/wsrep_mysqld.cc @@ -1778,7 +1778,6 @@ pthread_handler_t start_wsrep_THD(void *arg) } thd->real_id=pthread_self(); // Keep purify happy - thread_count++; thread_created++; threads.append(thd); @@ -1876,7 +1875,6 @@ pthread_handler_t start_wsrep_THD(void *arg) thd->unlink(); mysql_mutex_unlock(&LOCK_thread_count); delete thd; - dec_thread_count(); } my_thread_end(); return(NULL); |