806
by Brian Aker
Adding in an example singe thread scheduler |
1 |
/* Copyright (C) 2006 MySQL 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
|
15 |
||
16 |
#include <drizzled/server_includes.h> |
|
17 |
#include <drizzled/gettext.h> |
|
18 |
#include <drizzled/error.h> |
|
960.2.22
by Monty Taylor
Renamed a bunch of plugin files. |
19 |
#include <drizzled/plugin/scheduler.h> |
806
by Brian Aker
Adding in an example singe thread scheduler |
20 |
#include <drizzled/connect.h> |
21 |
#include <drizzled/sql_parse.h> |
|
22 |
#include <drizzled/session.h> |
|
23 |
#include <drizzled/connect.h> |
|
24 |
#include <string> |
|
25 |
using namespace std; |
|
26 |
||
960.1.1
by Monty Taylor
First pass at scheduler plugin. |
27 |
class Single_thread_scheduler : public Scheduler |
28 |
{
|
|
29 |
public: |
|
971.1.46
by Monty Taylor
Made plugin registration go through Plugin_registry. |
30 |
Single_thread_scheduler() |
31 |
: Scheduler(1) {} |
|
960.1.1
by Monty Taylor
First pass at scheduler plugin. |
32 |
|
33 |
virtual bool init_new_connection_thread(void) {return 0;} |
|
34 |
||
35 |
/*
|
|
36 |
Simple scheduler that use the main thread to handle the request
|
|
37 |
|
|
38 |
NOTES
|
|
39 |
This is only used for debugging, when starting mysqld with
|
|
40 |
--thread-handling=no-threads or --one-thread
|
|
41 |
|
|
42 |
When we enter this function, LOCK_thread_count is held!
|
|
43 |
*/
|
|
44 |
||
45 |
virtual bool add_connection(Session *session) |
|
46 |
{
|
|
47 |
handle_one_connection((void*) session); |
|
48 |
||
49 |
return false; |
|
50 |
}
|
|
51 |
||
52 |
||
53 |
/*
|
|
54 |
End connection, in case when we are using 'no-threads'
|
|
55 |
*/
|
|
56 |
||
57 |
virtual bool end_thread(Session *session, bool) |
|
58 |
{
|
|
59 |
unlink_session(session); /* locks LOCK_thread_count and deletes session */ |
|
60 |
||
61 |
return true; // Abort handle_one_connection |
|
62 |
}
|
|
63 |
||
64 |
||
65 |
virtual uint32_t count(void) |
|
66 |
{
|
|
67 |
return 0; |
|
68 |
}
|
|
69 |
||
70 |
};
|
|
929.1.1
by Brian Aker
Push thread count out to the scheduler. |
71 |
|
971.1.46
by Monty Taylor
Made plugin registration go through Plugin_registry. |
72 |
|
73 |
class SingleThreadFactory : public SchedulerFactory |
|
74 |
{
|
|
75 |
public: |
|
76 |
SingleThreadFactory() : SchedulerFactory("single_thread") {} |
|
77 |
~SingleThreadFactory() { if (scheduler != NULL) delete scheduler; } |
|
78 |
Scheduler *operator() () |
|
79 |
{
|
|
80 |
if (scheduler == NULL) |
|
81 |
scheduler= new Single_thread_scheduler(); |
|
82 |
return scheduler; |
|
83 |
}
|
|
84 |
};
|
|
85 |
||
971.1.51
by Monty Taylor
New-style plugin registration now works. |
86 |
SingleThreadFactory *factory= NULL; |
87 |
||
971.1.52
by Monty Taylor
Did the finalizers. Renamed plugin_registry. |
88 |
static int init(PluginRegistry ®istry) |
806
by Brian Aker
Adding in an example singe thread scheduler |
89 |
{
|
971.1.51
by Monty Taylor
New-style plugin registration now works. |
90 |
factory= new SingleThreadFactory(); |
971.1.52
by Monty Taylor
Did the finalizers. Renamed plugin_registry. |
91 |
registry.add(factory); |
806
by Brian Aker
Adding in an example singe thread scheduler |
92 |
return 0; |
93 |
}
|
|
94 |
||
971.1.52
by Monty Taylor
Did the finalizers. Renamed plugin_registry. |
95 |
static int deinit(PluginRegistry ®istry) |
806
by Brian Aker
Adding in an example singe thread scheduler |
96 |
{
|
971.1.51
by Monty Taylor
New-style plugin registration now works. |
97 |
if (factory) |
971.1.52
by Monty Taylor
Did the finalizers. Renamed plugin_registry. |
98 |
{
|
99 |
registry.remove(factory); |
|
971.1.51
by Monty Taylor
New-style plugin registration now works. |
100 |
delete factory; |
971.1.52
by Monty Taylor
Did the finalizers. Renamed plugin_registry. |
101 |
}
|
806
by Brian Aker
Adding in an example singe thread scheduler |
102 |
return 0; |
103 |
}
|
|
104 |
||
809
by Brian Aker
Refactor of scheduler plugin code to simplify around one structure. Also |
105 |
static struct st_mysql_sys_var* system_variables[]= { |
106 |
NULL
|
|
107 |
};
|
|
108 |
||
813.2.1
by Toru Maesaka
Renamed mysql_declare_plugin to drizzle_declare_plugin |
109 |
drizzle_declare_plugin(single_thread) |
806
by Brian Aker
Adding in an example singe thread scheduler |
110 |
{
|
111 |
"single_thread", |
|
112 |
"0.1", |
|
113 |
"Brian Aker", |
|
114 |
"Single Thread Scheduler", |
|
115 |
PLUGIN_LICENSE_GPL, |
|
116 |
init, /* Plugin Init */ |
|
117 |
deinit, /* Plugin Deinit */ |
|
118 |
NULL, /* status variables */ |
|
809
by Brian Aker
Refactor of scheduler plugin code to simplify around one structure. Also |
119 |
system_variables, /* system variables */ |
806
by Brian Aker
Adding in an example singe thread scheduler |
120 |
NULL /* config options */ |
121 |
}
|
|
813.2.2
by Toru Maesaka
Renamed mysql_declare_plugin_end to drizzle_declare_plugin_end |
122 |
drizzle_declare_plugin_end; |