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 <plugin/multi_thread/multi_thread.h>
19
using namespace drizzled;
21
/* Configuration variables. */
22
static uint32_t max_threads;
25
static MultiThreadScheduler *scheduler= NULL;
28
* Function to be run as a thread for each session.
32
extern "C" pthread_handler_t session_thread(void *arg);
37
extern "C" pthread_handler_t session_thread(void *arg)
39
Session *session= static_cast<Session*>(arg);
40
MultiThreadScheduler *scheduler= static_cast<MultiThreadScheduler*>(session->scheduler);
41
scheduler->runSession(session);
47
bool MultiThreadScheduler::addSession(Session *session)
49
if (thread_count >= max_threads)
54
if (pthread_create(&session->real_id, &attr, session_thread,
55
static_cast<void*>(session)))
65
void MultiThreadScheduler::killSessionNow(Session *session)
67
/* Locks LOCK_thread_count and deletes session */
68
unlink_session(session);
72
/* We should never reach this point. */
75
MultiThreadScheduler::~MultiThreadScheduler()
77
(void) pthread_mutex_lock(&LOCK_thread_count);
80
pthread_cond_wait(&COND_thread_count, &LOCK_thread_count);
83
(void) pthread_mutex_unlock(&LOCK_thread_count);
84
(void) pthread_attr_destroy(&attr);
88
static int init(drizzled::plugin::Registry ®istry)
90
scheduler= new MultiThreadScheduler("multi_thread");
91
registry.add(scheduler);
96
static int deinit(drizzled::plugin::Registry ®istry)
98
registry.remove(scheduler);
104
static DRIZZLE_SYSVAR_UINT(max_threads, max_threads,
106
N_("Maximum number of user threads available."),
107
NULL, NULL, 2048, 1, 4096, 0);
109
static struct st_mysql_sys_var* system_variables[]= {
110
DRIZZLE_SYSVAR(max_threads),
114
drizzle_declare_plugin(multi_thread)
119
"One Thread Per Session Scheduler",
121
init, /* Plugin Init */
122
deinit, /* Plugin Deinit */
123
NULL, /* status variables */
124
system_variables, /* system variables */
125
NULL /* config options */
127
drizzle_declare_plugin_end;