MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
thread_pool_priv.h
1 /*
2  Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #ifndef THREAD_POOL_PRIV_INCLUDED
19 #define THREAD_POOL_PRIV_INCLUDED
20 
21 /*
22  The thread pool requires access to some MySQL server error codes, this is
23  accessed from mysqld_error.h.
24  We need access to the struct that defines the thread pool plugin interface
25  which is accessed through scheduler.h.
26  All accesses to THD variables and functions are defined in this header file.
27  A thread pool can also use DEBUG_SYNC and must thus include
28  debug_sync.h
29  To handle definitions of Information Schema plugins it is also required
30  to include sql_profile.h and table.h.
31 */
32 #include <mysqld_error.h> /* To get ER_ERROR_ON_READ */
33 #define MYSQL_SERVER 1
34 #include <scheduler.h>
35 #include <debug_sync.h>
36 #include <sql_profile.h>
37 #include <table.h>
38 #include <set>
39 
40 typedef std::set<THD*>::iterator Thread_iterator;
41 /* Needed to get access to scheduler variables */
42 void* thd_get_scheduler_data(THD *thd);
43 void thd_set_scheduler_data(THD *thd, void *data);
44 PSI_thread* thd_get_psi(THD *thd);
45 void thd_set_psi(THD *thd, PSI_thread *psi);
46 
47 /* Interface to THD variables and functions */
48 void thd_set_killed(THD *thd);
49 void thd_clear_errors(THD *thd);
50 void thd_set_thread_stack(THD *thd, char *stack_start);
51 void thd_lock_thread_count(THD *thd);
52 void thd_unlock_thread_count(THD *thd);
53 void thd_close_connection(THD *thd);
54 THD *thd_get_current_thd();
55 void thd_new_connection_setup(THD *thd, char *stack_start);
56 void thd_lock_data(THD *thd);
57 void thd_unlock_data(THD *thd);
58 bool thd_is_transaction_active(THD *thd);
59 int thd_connection_has_data(THD *thd);
60 void thd_set_net_read_write(THD *thd, uint val);
61 uint thd_get_net_read_write(THD *thd);
62 void thd_set_mysys_var(THD *thd, st_my_thread_var *mysys_var);
63 ulong thd_get_net_wait_timeout(THD *thd);
64 my_socket thd_get_fd(THD *thd);
65 int thd_store_globals(THD* thd);
66 
67 /* Interface to global thread list iterator functions */
68 Thread_iterator thd_get_global_thread_list_begin();
69 Thread_iterator thd_get_global_thread_list_end();
70 
71 /* Print to the MySQL error log */
72 void sql_print_error(const char *format, ...);
73 
74 /* Store a table record */
75 bool schema_table_store_record(THD *thd, TABLE *table);
76 
77 /*
78  The thread pool must be able to execute statements using the connection
79  state in THD object. This is the main objective of the thread pool to
80  schedule the start of these commands.
81 */
82 bool do_command(THD *thd);
83 
84 /*
85  The thread pool requires an interface to the connection logic in the
86  MySQL Server since the thread pool will maintain the event logic on
87  the TCP connection of the MySQL Server. Thus new connections, dropped
88  connections will be discovered by the thread pool and it needs to
89  ensure that the proper MySQL Server logic attached to these events is
90  executed.
91 */
92 /* Initialise a new connection handler thread */
93 bool init_new_connection_handler_thread();
94 /* Set up connection thread before use as execution thread */
95 bool setup_connection_thread_globals(THD *thd);
96 /* Prepare connection as part of connection set-up */
97 bool thd_prepare_connection(THD *thd);
98 /* Release auditing before executing statement */
99 void mysql_audit_release(THD *thd);
100 /* Check if connection is still alive */
101 bool thd_is_connection_alive(THD *thd);
102 /* Close connection with possible error code */
103 void close_connection(THD *thd, uint errcode);
104 /* End the connection before closing it */
105 void end_connection(THD *thd);
106 /* Release resources of the THD object */
107 void thd_release_resources(THD *thd);
108 /* Decrement connection counter */
109 void dec_connection_count();
110 /* Destroy THD object */
111 void destroy_thd(THD *thd);
112 /* Remove the THD from the set of global threads. */
113 void remove_global_thread(THD *thd);
114 
115 /*
116  thread_created is maintained by thread pool when activated since
117  user threads are created by the thread pool (and also special
118  threads to maintain the thread pool). This is done through
119  inc_thread_created.
120 
121  max_connections is needed to calculate the maximum number of threads
122  that is allowed to be started by the thread pool. The method
123  get_max_connections() gets reference to this variable.
124 
125  connection_attrib is the thread attributes for connection threads,
126  the method get_connection_attrib provides a reference to these
127  attributes.
128 */
129 void inc_thread_created(void);
130 ulong get_max_connections(void);
131 pthread_attr_t *get_connection_attrib(void);
132 #endif