Commit de425ebd authored by Davi Arnaut's avatar Davi Arnaut

Fix for a valgrind warning due to use of a uninitialized

variable. The problem was that THD::connect_utime could be
used without being initialized when the main thread is used
to handle connections (--thread-handling=no-threads).

sql/mysqld.cc:
  Set THD::start_utime even in no-threads handling mode.
sql/sql_class.cc:
  Initialize variable.
sql/sql_class.h:
  Rename connect_utime to prior_thr_create_utime as to
  better reflect it's use intention.
sql/sql_connect.cc:
  Check only if a thread was actually created.
parent bee8ab6a
...@@ -4780,8 +4780,9 @@ void handle_connection_in_main_thread(THD *thd) ...@@ -4780,8 +4780,9 @@ void handle_connection_in_main_thread(THD *thd)
safe_mutex_assert_owner(&LOCK_thread_count); safe_mutex_assert_owner(&LOCK_thread_count);
thread_cache_size=0; // Safety thread_cache_size=0; // Safety
threads.append(thd); threads.append(thd);
(void) pthread_mutex_unlock(&LOCK_thread_count); pthread_mutex_unlock(&LOCK_thread_count);
handle_one_connection((void*) thd); thd->start_utime= my_micro_time();
handle_one_connection(thd);
} }
...@@ -4806,7 +4807,7 @@ void create_thread_to_handle_connection(THD *thd) ...@@ -4806,7 +4807,7 @@ void create_thread_to_handle_connection(THD *thd)
thread_created++; thread_created++;
threads.append(thd); threads.append(thd);
DBUG_PRINT("info",(("creating thread %lu"), thd->thread_id)); DBUG_PRINT("info",(("creating thread %lu"), thd->thread_id));
thd->connect_utime= thd->start_utime= my_micro_time(); thd->prior_thr_create_utime= thd->start_utime= my_micro_time();
if ((error=pthread_create(&thd->real_id,&connection_attrib, if ((error=pthread_create(&thd->real_id,&connection_attrib,
handle_one_connection, handle_one_connection,
(void*) thd))) (void*) thd)))
......
...@@ -590,7 +590,7 @@ THD::THD() ...@@ -590,7 +590,7 @@ THD::THD()
// Must be reset to handle error with THD's created for init of mysqld // Must be reset to handle error with THD's created for init of mysqld
lex->current_select= 0; lex->current_select= 0;
start_time=(time_t) 0; start_time=(time_t) 0;
start_utime= 0L; start_utime= prior_thr_create_utime= 0L;
utime_after_lock= 0L; utime_after_lock= 0L;
current_linfo = 0; current_linfo = 0;
slave_thread = 0; slave_thread = 0;
......
...@@ -1370,7 +1370,8 @@ class THD :public Statement, ...@@ -1370,7 +1370,8 @@ class THD :public Statement,
/* remote (peer) port */ /* remote (peer) port */
uint16 peer_port; uint16 peer_port;
time_t start_time, user_time; time_t start_time, user_time;
ulonglong connect_utime, thr_create_utime; // track down slow pthread_create // track down slow pthread_create
ulonglong prior_thr_create_utime, thr_create_utime;
ulonglong start_utime, utime_after_lock; ulonglong start_utime, utime_after_lock;
thr_lock_type update_lock_default; thr_lock_type update_lock_default;
......
...@@ -1074,8 +1074,8 @@ static void prepare_new_connection_state(THD* thd) ...@@ -1074,8 +1074,8 @@ static void prepare_new_connection_state(THD* thd)
pthread_handler_t handle_one_connection(void *arg) pthread_handler_t handle_one_connection(void *arg)
{ {
THD *thd= (THD*) arg; THD *thd= (THD*) arg;
ulong launch_time= (ulong) ((thd->thr_create_utime= my_micro_time()) -
thd->connect_utime); thd->thr_create_utime= my_micro_time();
if (thread_scheduler.init_new_connection_thread()) if (thread_scheduler.init_new_connection_thread())
{ {
...@@ -1084,8 +1084,20 @@ pthread_handler_t handle_one_connection(void *arg) ...@@ -1084,8 +1084,20 @@ pthread_handler_t handle_one_connection(void *arg)
thread_scheduler.end_thread(thd,0); thread_scheduler.end_thread(thd,0);
return 0; return 0;
} }
if (launch_time >= slow_launch_time*1000000L)
statistic_increment(slow_launch_threads,&LOCK_status); /*
If a thread was created to handle this connection:
increment slow_launch_threads counter if it took more than
slow_launch_time seconds to create the thread.
*/
if (thd->prior_thr_create_utime)
{
ulong launch_time= (ulong) (thd->thr_create_utime -
thd->prior_thr_create_utime);
if (launch_time >= slow_launch_time*1000000L)
statistic_increment(slow_launch_threads, &LOCK_status);
thd->prior_thr_create_utime= 0;
}
/* /*
handle_one_connection() is normally the only way a thread would handle_one_connection() is normally the only way a thread would
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment