1#ifndef SCHEDULER_INCLUDED
2#define SCHEDULER_INCLUDED
3
4/* Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
5 Copyright (c) 2012, Monty Program Ab
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; version 2 of the License.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
19
20/*
21 Classes for the thread scheduler
22*/
23
24#ifdef USE_PRAGMA_INTERFACE
25#pragma interface
26#endif
27
28class THD;
29
30/* Functions used when manipulating threads */
31
32struct scheduler_functions
33{
34 uint max_threads, *connection_count;
35 ulong *max_connections;
36 bool (*init)(void);
37 bool (*init_new_connection_thread)(void);
38 void (*add_connection)(CONNECT *connect);
39 void (*thd_wait_begin)(THD *thd, int wait_type);
40 void (*thd_wait_end)(THD *thd);
41 void (*post_kill_notification)(THD *thd);
42 bool (*end_thread)(THD *thd, bool cache_thread);
43 void (*end)(void);
44};
45
46
47/**
48 Scheduler types enumeration.
49
50 The default of --thread-handling is the first one in the
51 thread_handling_names array, this array has to be consistent with
52 the order in this array, so to change default one has to change the
53 first entry in this enum and the first entry in the
54 thread_handling_names array.
55
56 @note The last entry of the enumeration is also used to mark the
57 thread handling as dynamic. In this case the name of the thread
58 handling is fetched from the name of the plugin that implements it.
59*/
60enum scheduler_types
61{
62 /*
63 The default of --thread-handling is the first one in the
64 thread_handling_names array, this array has to be consistent with
65 the order in this array, so to change default one has to change
66 the first entry in this enum and the first entry in the
67 thread_handling_names array.
68 */
69 SCHEDULER_ONE_THREAD_PER_CONNECTION=0,
70 SCHEDULER_NO_THREADS,
71 SCHEDULER_TYPES_COUNT
72};
73
74void one_thread_per_connection_scheduler(scheduler_functions *func,
75 ulong *arg_max_connections, uint *arg_connection_count);
76void one_thread_scheduler(scheduler_functions *func);
77
78extern void scheduler_init();
79extern void post_kill_notification(THD *);
80/*
81 To be used for pool-of-threads (implemeneted differently on various OSs)
82*/
83struct thd_scheduler
84{
85public:
86 /*
87 Thread instrumentation for the user job.
88 This member holds the instrumentation while the user job is not run
89 by a thread.
90
91 Note that this member is not conditionally declared
92 (ifdef HAVE_PSI_INTERFACE), because doing so will change the binary
93 layout of THD, which is exposed to plugin code that may be compiled
94 differently.
95 */
96 PSI_thread *m_psi;
97 void *data; /* scheduler-specific data structure */
98};
99
100#ifdef HAVE_POOL_OF_THREADS
101void pool_of_threads_scheduler(scheduler_functions* func,
102 ulong *arg_max_connections,
103 uint *arg_connection_count);
104#else
105#define pool_of_threads_scheduler(A,B,C) \
106 one_thread_per_connection_scheduler(A, B, C)
107#endif /*HAVE_POOL_OF_THREADS*/
108
109#endif /* SCHEDULER_INCLUDED */
110