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等函數,走在該文件中實現




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章