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 */
17
#include <plugin/multi_thread/multi_thread.h>
18
#include "drizzled/pthread_globals.h"
21
using namespace drizzled;
23
/* Configuration variables. */
24
static uint32_t max_threads;
27
static MultiThreadScheduler *scheduler= NULL;
30
* Function to be run as a thread for each session.
34
extern "C" pthread_handler_t session_thread(void *arg);
39
extern "C" pthread_handler_t session_thread(void *arg)
41
Session *session= static_cast<Session*>(arg);
42
MultiThreadScheduler *sched= static_cast<MultiThreadScheduler*>(session->scheduler);
43
sched->runSession(session);
49
bool MultiThreadScheduler::addSession(Session *session)
51
if (thread_count >= max_threads)
56
if (pthread_create(&session->real_id, &attr, session_thread,
57
static_cast<void*>(session)))
67
void MultiThreadScheduler::killSessionNow(Session *session)
69
/* Locks LOCK_thread_count and deletes session */
70
Session::unlink(session);
74
/* We should never reach this point. */
77
MultiThreadScheduler::~MultiThreadScheduler()
79
(void) pthread_mutex_lock(&LOCK_thread_count);
82
pthread_cond_wait(&COND_thread_count, &LOCK_thread_count);
85
(void) pthread_mutex_unlock(&LOCK_thread_count);
86
(void) pthread_attr_destroy(&attr);
90
static int init(drizzled::plugin::Registry ®istry)
92
scheduler= new MultiThreadScheduler("multi_thread");
93
registry.add(scheduler);
98
static int deinit(drizzled::plugin::Registry ®istry)
100
registry.remove(scheduler);
106
static DRIZZLE_SYSVAR_UINT(max_threads, max_threads,
108
N_("Maximum number of user threads available."),
109
NULL, NULL, 2048, 1, 4096, 0);
111
static drizzle_sys_var* system_variables[]= {
112
DRIZZLE_SYSVAR(max_threads),
116
DRIZZLE_DECLARE_PLUGIN
122
"One Thread Per Session Scheduler",
124
init, /* Plugin Init */
125
deinit, /* Plugin Deinit */
126
NULL, /* status variables */
127
system_variables, /* system variables */
128
NULL /* config options */
130
DRIZZLE_DECLARE_PLUGIN_END;