summaryrefslogtreecommitdiff
path: root/sql/threadpool_common.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/threadpool_common.cc')
-rw-r--r--sql/threadpool_common.cc57
1 files changed, 31 insertions, 26 deletions
diff --git a/sql/threadpool_common.cc b/sql/threadpool_common.cc
index fc9a79432f0..7de7866e015 100644
--- a/sql/threadpool_common.cc
+++ b/sql/threadpool_common.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2012 Monty Program Ab
+/* Copyright (C) 2012, 2020, MariaDB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -13,7 +13,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
-#include <my_global.h>
+#include "mariadb.h"
#include <violite.h>
#include <sql_priv.h>
#include <sql_class.h>
@@ -83,17 +83,13 @@ struct Worker_thread_context
void save()
{
-#ifdef HAVE_PSI_THREAD_INTERFACE
- psi_thread = PSI_THREAD_CALL(get_thread)();
-#endif
+ psi_thread= PSI_CALL_get_thread();
mysys_var= my_thread_var;
}
void restore()
{
-#ifdef HAVE_PSI_THREAD_INTERFACE
- PSI_THREAD_CALL(set_thread)(psi_thread);
-#endif
+ PSI_CALL_set_thread(psi_thread);
set_mysys_var(mysys_var);
pthread_setspecific(THR_THD, 0);
}
@@ -143,9 +139,7 @@ static void thread_attach(THD* thd)
set_mysys_var(thd->mysys_var);
thd->thread_stack=(char*)&thd;
thd->store_globals();
-#ifdef HAVE_PSI_THREAD_INTERFACE
- PSI_THREAD_CALL(set_thread)(thd->event_scheduler.m_psi);
-#endif
+ PSI_CALL_set_thread(thd->event_scheduler.m_psi);
mysql_socket_set_thread_owner(thd->net.vio->mysql_socket);
}
@@ -176,7 +170,7 @@ void tp_callback(TP_connection *c)
c->state = TP_STATE_RUNNING;
- if (!thd)
+ if (unlikely(!thd))
{
/* No THD, need to login first. */
DBUG_ASSERT(c->connect);
@@ -190,7 +184,7 @@ void tp_callback(TP_connection *c)
}
else if (threadpool_process_request(thd))
{
- /* QUIT or an error occured. */
+ /* QUIT or an error occurred. */
goto error;
}
@@ -198,7 +192,7 @@ void tp_callback(TP_connection *c)
c->priority= get_priority(c);
/* Read next command from client. */
- c->set_io_timeout(thd->variables.net_wait_timeout);
+ c->set_io_timeout(thd->get_net_wait_timeout());
c->state= TP_STATE_IDLE;
if (c->start_io())
goto error;
@@ -208,12 +202,11 @@ void tp_callback(TP_connection *c)
error:
c->thd= 0;
- delete c;
-
if (thd)
{
threadpool_remove_connection(thd);
}
+ delete c;
worker_context.restore();
}
@@ -249,14 +242,12 @@ static THD* threadpool_add_connection(CONNECT *connect, void *scheduler_data)
}
delete connect;
add_to_active_threads(thd);
- thd->mysys_var= mysys_var;
+ thd->set_mysys_var(mysys_var);
thd->event_scheduler.data= scheduler_data;
/* Create new PSI thread for use with the THD. */
-#ifdef HAVE_PSI_THREAD_INTERFACE
thd->event_scheduler.m_psi=
- PSI_THREAD_CALL(new_thread)(key_thread_one_connection, thd, thd->thread_id);
-#endif
+ PSI_CALL_new_thread(key_thread_one_connection, thd, thd->thread_id);
/* Login. */
@@ -484,12 +475,26 @@ void tp_timeout_handler(TP_connection *c)
{
if (c->state != TP_STATE_IDLE)
return;
- THD *thd=c->thd;
- mysql_mutex_lock(&thd->LOCK_thd_data);
- thd->set_killed(KILL_WAIT_TIMEOUT);
- c->priority= TP_PRIORITY_HIGH;
- post_kill_notification(thd);
- mysql_mutex_unlock(&thd->LOCK_thd_data);
+ THD *thd= c->thd;
+ mysql_mutex_lock(&thd->LOCK_thd_kill);
+ Vio *vio= thd->net.vio;
+ if (vio && (vio_pending(vio) > 0 || vio->has_data(vio)) &&
+ c->state == TP_STATE_IDLE)
+ {
+ /*
+ There is some data on that connection, i.e
+ i.e there was no inactivity timeout.
+ Don't kill.
+ */
+ c->state= TP_STATE_PENDING;
+ }
+ else if (c->state == TP_STATE_IDLE)
+ {
+ thd->set_killed_no_mutex(KILL_WAIT_TIMEOUT);
+ c->priority= TP_PRIORITY_HIGH;
+ post_kill_notification(thd);
+ }
+ mysql_mutex_unlock(&thd->LOCK_thd_kill);
}