1
/* Copyright (C) 2006 MySQL AB
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.
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.
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 */
16
#include <drizzled/server_includes.h>
17
#include <drizzled/gettext.h>
18
#include <drizzled/error.h>
19
#include <drizzled/plugin_scheduling.h>
20
#include <drizzled/connect.h>
21
#include <drizzled/sql_parse.h>
22
#include <drizzled/session.h>
23
#include <drizzled/connect.h>
27
pthread_attr_t multi_thread_attrib;
28
static uint32_t max_threads;
30
static bool add_connection(Session *session)
34
safe_mutex_assert_owner(&LOCK_thread_count);
35
(void) pthread_mutex_unlock(&LOCK_thread_count);
37
if ((error= pthread_create(&session->real_id, &multi_thread_attrib, handle_one_connection, (void*) session)))
45
End connection, in case when we are using 'no-threads'
48
static bool end_thread(Session *session, bool)
50
unlink_session(session); /* locks LOCK_thread_count and deletes session */
51
pthread_mutex_unlock(&LOCK_thread_count);
54
return true; // We should never reach this point
57
static int init(void *p)
59
scheduling_st* func= (scheduling_st *)p;
61
func->max_threads= max_threads; /* This will create an upper limit on max connections */
62
func->add_connection= add_connection;
63
func->end_thread= end_thread;
65
/* Parameter for threads created for connections */
66
(void) pthread_attr_init(&multi_thread_attrib);
67
(void) pthread_attr_setdetachstate(&multi_thread_attrib,
68
PTHREAD_CREATE_DETACHED);
69
pthread_attr_setscope(&multi_thread_attrib, PTHREAD_SCOPE_SYSTEM);
74
static int deinit(void *)
76
pthread_attr_destroy(&multi_thread_attrib);
81
static DRIZZLE_SYSVAR_UINT(max_threads, max_threads,
83
N_("Maximum number of user threads available."),
84
NULL, NULL, 2048, 1, 4048, 0);
86
static struct st_mysql_sys_var* system_variables[]= {
87
DRIZZLE_SYSVAR(max_threads),
91
drizzle_declare_plugin(multi_thread)
93
DRIZZLE_SCHEDULING_PLUGIN,
97
"One Thread Perl Session Scheduler",
99
init, /* Plugin Init */
100
deinit, /* Plugin Deinit */
101
NULL, /* status variables */
102
system_variables, /* system variables */
103
NULL /* config options */
105
drizzle_declare_plugin_end;