1 /* Copyright (C) 2012 Monty Program Ab
2 
3    This program is free software; you can redistribute it and/or modify
4    it under the terms of the GNU General Public License as published by
5    the Free Software Foundation; version 2 of the License.
6 
7    This program is distributed in the hope that it will be useful,
8    but WITHOUT ANY WARRANTY; without even the implied warranty of
9    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10    GNU General Public License for more details.
11 
12    You should have received a copy of the GNU General Public License
13    along with this program; if not, write to the Free Software
14    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,  USA */
15 #ifndef THREADPOOL_INCLUDED
16 #define THREADPOOL_INCLUDED
17 
18 #include "conn_handler/connection_handler_manager.h"
19 
20 #define MAX_THREAD_GROUPS 128
21 
22 enum tp_high_prio_mode_t {
23   TP_HIGH_PRIO_MODE_TRANSACTIONS,
24   TP_HIGH_PRIO_MODE_STATEMENTS,
25   TP_HIGH_PRIO_MODE_NONE
26 };
27 
28 typedef struct st_mysql_show_var SHOW_VAR;
29 
30 /* Threadpool parameters */
31 extern uint threadpool_min_threads;  /* Minimum threads in pool */
32 extern uint threadpool_idle_timeout; /* Shutdown idle worker threads  after this timeout */
33 extern uint threadpool_size; /* Number of parallel executing threads */
34 extern uint threadpool_stall_limit;  /* time interval in 10 ms units for stall checks*/
35 extern uint threadpool_max_threads;  /* Maximum threads in pool */
36 extern uint threadpool_oversubscribe;  /* Maximum active threads in group */
37 
38 /* Possible values for thread_pool_high_prio_mode */
39 extern const char *threadpool_high_prio_mode_names[];
40 
41 /* Common thread pool routines, suitable for different implementations */
42 extern void threadpool_remove_connection(THD *thd);
43 extern int  threadpool_process_request(THD *thd);
44 extern int  threadpool_add_connection(THD *thd);
45 
46 /*
47   Functions used by scheduler.
48   OS-specific implementations are in
49   threadpool_unix.cc or threadpool_win.cc
50 */
51 extern bool tp_init();
52 extern void tp_wait_begin(THD *, int);
53 extern void tp_wait_end(THD*);
54 extern void tp_post_kill_notification(THD *thd);
55 extern void tp_end(void);
56 
57 extern THD_event_functions tp_event_functions;
58 
59 /* Used in SHOW for threadpool_idle_thread_count */
60 extern int  tp_get_idle_thread_count();
61 
62 /*
63   Threadpool statistics
64 */
65 struct TP_STATISTICS
66 {
67   /* Current number of worker thread. */
68   volatile int32 num_worker_threads;
69 };
70 
71 extern TP_STATISTICS tp_stats;
72 
73 
74 /* Functions to set threadpool parameters */
75 extern void tp_set_min_threads(uint val);
76 extern void tp_set_max_threads(uint val);
77 extern void tp_set_threadpool_size(uint val);
78 extern void tp_set_threadpool_stall_limit(uint val);
79 
80 #endif /* THREADPOOL_INCLUDED */
81