summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libmysqld/lib_sql.cc2
-rw-r--r--plugin/feedback/sender_thread.cc2
-rw-r--r--plugin/handler_socket/handlersocket/database.cpp2
-rw-r--r--sql/event_scheduler.cc1
-rw-r--r--sql/mysqld.cc27
-rw-r--r--sql/mysqld.h1
-rw-r--r--sql/scheduler.cc1
-rw-r--r--sql/sql_class.cc2
-rw-r--r--sql/sql_class.h14
-rw-r--r--sql/sql_connect.cc24
-rw-r--r--sql/sql_insert.cc2
-rw-r--r--sql/sql_parse.cc9
-rw-r--r--sql/threadpool_common.cc1
-rw-r--r--sql/wsrep_mysqld.cc2
14 files changed, 22 insertions, 68 deletions
diff --git a/libmysqld/lib_sql.cc b/libmysqld/lib_sql.cc
index 7855a5f2a73..8ce11ebff0e 100644
--- a/libmysqld/lib_sql.cc
+++ b/libmysqld/lib_sql.cc
@@ -426,7 +426,6 @@ static void emb_free_embedded_thd(MYSQL *mysql)
THD *thd= (THD*)mysql->thd;
mysql_mutex_lock(&LOCK_thread_count);
thd->clear_data_list();
- thread_count--;
thd->store_globals();
thd->unlink();
mysql_mutex_unlock(&LOCK_thread_count);
@@ -700,7 +699,6 @@ void *create_embedded_thd(int client_flag)
bzero((char*) &thd->net, sizeof(thd->net));
mysql_mutex_lock(&LOCK_thread_count);
- thread_count++;
threads.append(thd);
mysql_mutex_unlock(&LOCK_thread_count);
thd->mysys_var= 0;
diff --git a/plugin/feedback/sender_thread.cc b/plugin/feedback/sender_thread.cc
index 1b90d2cb340..16cdfe5574a 100644
--- a/plugin/feedback/sender_thread.cc
+++ b/plugin/feedback/sender_thread.cc
@@ -91,7 +91,6 @@ static int prepare_for_fill(TABLE_LIST *tables)
*/
thd->variables.pseudo_thread_id= thd->thread_id;
mysql_mutex_lock(&LOCK_thread_count);
- thread_count++;
threads.append(thd);
mysql_mutex_unlock(&LOCK_thread_count);
thd->thread_stack= (char*) &tables;
@@ -263,7 +262,6 @@ ret:
*/
mysql_mutex_lock(&LOCK_thread_count);
thd->set_status_var_init();
- thread_count--;
thd->killed= KILL_CONNECTION;
thd->unlink();
mysql_cond_broadcast(&COND_thread_count);
diff --git a/plugin/handler_socket/handlersocket/database.cpp b/plugin/handler_socket/handlersocket/database.cpp
index 28ce6c78876..4292b826753 100644
--- a/plugin/handler_socket/handlersocket/database.cpp
+++ b/plugin/handler_socket/handlersocket/database.cpp
@@ -310,7 +310,6 @@ dbcontext::init_thread(const void *stack_bottom, volatile int& shutdown_flag)
}
{
thd->thread_id = next_thread_id();
- thread_safe_increment32(&thread_count);
add_to_active_threads(thd);
}
@@ -348,7 +347,6 @@ dbcontext::term_thread()
pthread_mutex_lock(&LOCK_thread_count);
delete thd;
thd = 0;
- --thread_count;
pthread_mutex_unlock(&LOCK_thread_count);
my_thread_end();
}
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);