首页 > 代码库 > mysql源码---核心类 (1)线程类
mysql源码---核心类 (1)线程类
线程是mysql一个很重要的概念。线程用来处理来自客户端的连接,线程和连接是1:1的关。线程和THD对象也是1:1对应的关系,有些线程会被设置为优先,而有些线程没有优先级,而线程的优先级设置在sql/mysql_priv.h
#define INTERRUPT_PRIOR -2
#define CONNECT_PRIOR -1
#define WAIT_PRIOR 0
#define QUERY_PRIOR 2
(THD是mysql线程描述符类)
线程初始化工作:
void THD::init(void)
{
pthread_mutex_lock(&LOCK_global_system_variables);
plugin_thdvar_init(this);
variables.time_format= date_time_format_copy((THD*) 0,
variables.time_format);
variables.date_format= date_time_format_copy((THD*) 0,
variables.date_format);
variables.datetime_format= date_time_format_copy((THD*) 0,
variables.datetime_format);
/*
variables= global_system_variables above has reset
variables.pseudo_thread_id to 0. We need to correct it here to
avoid temporary tables replication failure.
*/
variables.pseudo_thread_id= thread_id;
pthread_mutex_unlock(&LOCK_global_system_variables);
server_status= SERVER_STATUS_AUTOCOMMIT;
if (variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES)
server_status|= SERVER_STATUS_NO_BACKSLASH_ESCAPES;
options= thd_startup_options;
if (variables.max_join_size == HA_POS_ERROR)
options |= OPTION_BIG_SELECTS;
else
options &= ~OPTION_BIG_SELECTS;
transaction.all.modified_non_trans_table= transaction.stmt.modified_non_trans_table= FALSE;
open_options=ha_open_options;
update_lock_default= (variables.low_priority_updates ?
TL_WRITE_LOW_PRIORITY :
TL_WRITE);
session_tx_isolation= (enum_tx_isolation) variables.tx_isolation;
update_charset();
reset_current_stmt_binlog_row_based();
bzero((char *) &status_var, sizeof(status_var));
sql_log_bin_toplevel= options & OPTION_BIN_LOG;
#if defined(ENABLED_DEBUG_SYNC)
/* Initialize the Debug Sync Facility. See debug_sync.cc. */
debug_sync_init_thread(this);
#endif /* defined(ENABLED_DEBUG_SYNC) */
}
还有一些cleanup等函数,走在该文件中实现
本文出自 “Linux运维” 博客,请务必保留此出处http://2853725.blog.51cto.com/2843725/1544160
mysql源码---核心类 (1)线程类