diff options
author | Mikael Ronström <mikael@dator9> | 2011-02-16 19:30:02 +0100 |
---|---|---|
committer | Mikael Ronström <mikael@dator9> | 2011-02-16 19:30:02 +0100 |
commit | e5b98b918d05257aca7a066e979c5cbe93851f2d (patch) | |
tree | 6c191e9d250ac1c672e3dea01bf6df7e7794c746 /sql/sql_class.cc | |
parent | 503294a268893121b9bbccb6c48e5f57c246864e (diff) | |
download | mariadb-git-e5b98b918d05257aca7a066e979c5cbe93851f2d.tar.gz |
Defined private interface to THD variables, first step to plugin API
Diffstat (limited to 'sql/sql_class.cc')
-rw-r--r-- | sql/sql_class.cc | 196 |
1 files changed, 196 insertions, 0 deletions
diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 3067b86d5e1..43e55f27502 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -217,26 +217,222 @@ bool foreign_key_prefix(Key *a, Key *b) ** Thread specific functions ****************************************************************************/ +/** + Get reference to scheduler data object + + @param thd THD object + + @retval Scheduler data object on THD +*/ void *thd_get_scheduler_data(THD *thd) { return thd->scheduler.data; } +/** + Set reference to Scheduler data object for THD object + + @param thd THD object + @param psi Scheduler data object to set on THD +*/ void thd_set_scheduler_data(THD *thd, void *data) { thd->scheduler.data= data; } +/** + Get reference to Performance Schema object for THD object + + @param thd THD object + + @retval Performance schema object for thread on THD +*/ PSI_thread *thd_get_psi(THD *thd) { return thd->scheduler.m_psi; } +/** + Set reference to Performance Schema object for THD object + + @param thd THD object + @param psi Performance schema object for thread +*/ void thd_set_psi(THD *thd, PSI_thread *psi) { thd->scheduler.m_psi= psi; } +/** + Set the state on connection to killed + + @param thd THD object +*/ +void thd_set_killed(THD *thd) +{ + thd->killed= THD::KILL_CONNECTION; +} + +/** + Clear errors from the previous THD + + @param thd THD object +*/ +void thd_clear_errors(THD *thd) +{ + my_errno= 0; + thd->mysys_var->abort= 0; +} + +/** + Set thread stack in THD object + + @param thd Thread object + @param stack_start Start of stack to set in THD object +*/ +void thd_set_thread_stack(THD *thd, char *stack_start) +{ + thd->thread_stack= stack_start; +} + +/** + Lock connection data for the set of connections this connection + belongs to + + @param thd THD object +*/ +void thd_lock_connection_data(THD *thd) +{ + (void)thd; + mysql_mutex_lock(&LOCK_thread_count); +} + +/** + Lock connection data for the set of connections this connection + belongs to + + @param thd THD object +*/ +void thd_unlock_connection_data(THD *thd) +{ + (void)thd; + mysql_cond_broadcast(&COND_thread_count); + mysql_mutex_unlock(&LOCK_thread_count); +} + +/** + Close the socket used by this connection + + @param thd THD object +*/ +void thd_close_connection(THD *thd) +{ + if (thd->net.vio) + vio_close(thd->net.vio); +} + +/** + Get current THD object from thread local data + + @retval The THD object for the thread, NULL if not connection thread +*/ +THD *thd_get_current_thd() +{ + return current_thd; +} + +/** + Set up various THD data for a new connection + + thd_new_connection_setup + + @param thd THD object + @param stack_start Start of stack for connection +*/ +void thd_new_connection_setup(THD *thd, char *stack_start) +{ +#ifdef HAVE_PSI_INTERFACE + if (PSI_server) + thd_set_psi(thd, + PSI_server->new_thread(key_thread_one_connection, + thd, + thd_get_thread_id((MYSQL_THD)thd))); +#endif + thd->set_time(); + thd->prior_thr_create_utime= thd->thr_create_utime= thd->start_utime= + my_micro_time(); + threads.append(thd); + thd_unlock_connection_data(thd); + DBUG_PRINT("info", ("init new connection. thd: 0x%lx fd: %d", + (ulong)thd, thd->net.vio->sd)); + thd_set_thread_stack(thd, stack_start); +} + +/** + Lock data that needs protection in THD object + + @param thd THD object +*/ +void thd_lock_data(THD *thd) +{ + mysql_mutex_lock(&thd->LOCK_thd_data); +} + +/** + Unlock data that needs protection in THD object + + @param thd THD object +*/ +void thd_unlock_data(THD *thd) +{ + mysql_mutex_unlock(&thd->LOCK_thd_data); +} + +/** + Support method to check if connection has already started transcaction + + @param client_cntx Low level client context + + @retval TRUE if connection already started transaction +*/ +bool thd_is_transaction_active(THD *thd) +{ + return thd->transaction.is_active(); +} + +/** + Check if there is buffered data on the socket representing the connection + + @param thd THD object +*/ +int thd_connection_has_data(THD *thd) +{ + Vio *vio= thd->net.vio; + return vio->has_data(vio); +} + +/** + Set reading/writing on socket, used by SHOW PROCESSLIST + + @param thd THD object + @param val Value to set it to (0 or 1) +*/ +void thd_set_net_read_write(THD *thd, uint val) +{ + thd->net.reading_or_writing= val; +} + +/** + Set reference to mysys variable in THD object + + @param thd THD object + @param mysys_var Reference to set +*/ +void thd_set_mysys_var(THD *thd, st_my_thread_var *mysys_var) +{ + thd->set_mysys_var(mysys_var); +} + /* The following functions form part of the C plugin API */ |