Commit e5b98b91 authored by Mikael Ronström's avatar Mikael Ronström

Defined private interface to THD variables, first step to plugin API

parent 503294a2
......@@ -39,8 +39,26 @@
#include <table.h>
/* Needed to get access to scheduler variables */
void* thd_get_scheduler(THD *thd);
void* thd_get_scheduler_data(THD *thd);
void thd_set_scheduler_data(THD *thd, void *data);
PSI_thread* thd_get_psi(THD *thd);
void thd_set_psi(THD *thd, PSI_thread *psi);
/* Interface to THD variables and functions */
void thd_set_killed(THD *thd);
void thd_clear_errors(THD *thd);
void thd_set_thread_stack(THD *thd, char *stack_start);
void thd_lock_connection_data(THD *thd);
void thd_unlock_connection_data(THD *thd);
void thd_close_connection(THD *thd);
THD *thd_get_current_thd();
void thd_new_connection_setup(THD *thd, char *stack_start);
void thd_lock_data(THD *thd);
void thd_unlock_data(THD *thd);
bool thd_is_transaction_active(THD *thd);
int thd_connection_has_data(THD *thd);
void thd_set_net_read_write(THD *thd, uint val);
void thd_set_mysys_var(THD *thd, st_my_thread_var *mysys_var);
/*
The thread pool must be able to execute commands using the connection
......
......@@ -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
*/
......
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