4750 Tor Didriksen 2012-10-17 [merge]
merge 5.6 => trunk
modified:
sql/global_threads.h
sql/sql_show.cc
4749 Sneha Modi 2012-10-17 [merge]
null-merge from 5.6 -> trunk
=== modified file 'sql/global_threads.h'
--- a/sql/global_threads.h 2012-10-01 05:05:24 +0000
+++ b/sql/global_threads.h 2012-10-17 14:54:09 +0000
@@ -26,9 +26,10 @@ extern mysql_mutex_t LOCK_thread_count;
extern mysql_mutex_t LOCK_thread_remove;
extern mysql_cond_t COND_thread_count;
-/*
+/**
We maintail a set of all registered threads.
We provide acccessors to iterate over all threads.
+ There is no guarantee on the order of THDs when iterating.
We also provide mutators for inserting, and removing an element:
add_global_thread() inserts a THD into the set, and increments the counter.
=== modified file 'sql/sql_show.cc'
--- a/sql/sql_show.cc 2012-10-08 14:44:25 +0000
+++ b/sql/sql_show.cc 2012-10-17 14:54:09 +0000
@@ -1977,7 +1977,8 @@ view_store_create_info(THD *thd, TABLE_L
returns for each thread: thread id, user, host, db, command, info
****************************************************************************/
-class thread_info :public ilink<thread_info> {
+class thread_info
+{
public:
static void *operator new(size_t size)
{
@@ -1994,6 +1995,17 @@ public:
CSET_STRING query_string;
};
+// For sorting by thread_id.
+class thread_info_compare :
+ public std::binary_function<const thread_info*, const thread_info*, bool>
+{
+public:
+ bool operator() (const thread_info* p1, const thread_info* p2)
+ {
+ return p1->thread_id < p2->thread_id;
+ }
+};
+
static const char *thread_state_info(THD *tmp)
{
#ifndef EMBEDDED_LIBRARY
@@ -2022,7 +2034,7 @@ void mysqld_list_processes(THD *thd,cons
{
Item *field;
List<Item> field_list;
- I_List<thread_info> thread_infos;
+ Mem_root_array<thread_info*, true> thread_infos(thd->mem_root);
ulong max_query_length= (verbose ? thd->variables.max_allowed_packet :
PROCESS_LIST_WIDTH);
Protocol *protocol= thd->protocol;
@@ -2047,6 +2059,7 @@ void mysqld_list_processes(THD *thd,cons
if (!thd->killed)
{
mysql_mutex_lock(&LOCK_thread_count);
+ thread_infos.reserve(get_thread_count());
Thread_iterator it= global_thread_list_begin();
Thread_iterator end= global_thread_list_end();
for (; it != end; ++it)
@@ -2096,16 +2109,19 @@ void mysqld_list_processes(THD *thd,cons
}
mysql_mutex_unlock(&tmp->LOCK_thd_data);
thd_info->start_time= tmp->start_time.tv_sec;
- thread_infos.push_front(thd_info);
+ thread_infos.push_back(thd_info);
}
}
mysql_mutex_unlock(&LOCK_thread_count);
}
- thread_info *thd_info;
+ // Return list sorted by thread_id.
+ std::sort(thread_infos.begin(), thread_infos.end(), thread_info_compare());
+
time_t now= my_time(0);
- while ((thd_info=thread_infos.get()))
+ for (size_t ix= 0; ix < thread_infos.size(); ++ix)
{
+ thread_info *thd_info= thread_infos.at(ix);
protocol->prepare_for_resend();
protocol->store((ulonglong) thd_info->thread_id);
protocol->store(thd_info->user, system_charset_info);
No bundle (reason: useless for push emails).
| Thread |
|---|
| • bzr push into mysql-trunk branch (tor.didriksen:4749 to 4750) | Tor Didriksen | 18 Oct |