~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/single_thread/single_thread.cc

  • Committer: Monty Taylor
  • Date: 2009-01-25 14:29:57 UTC
  • mfrom: (811 drizzle)
  • mto: (779.7.3 devel)
  • mto: This revision was merged to the branch mainline in revision 816.
  • Revision ID: mordred@inaugust.com-20090125142957-qd2dc0x4lbdeut84
MergedĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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>
 
19
#include <drizzled/plugin_scheduling.h>
 
20
#include <drizzled/serialize/serialize.h>
 
21
#include <drizzled/connect.h>
 
22
#include <drizzled/sql_parse.h>
 
23
#include <drizzled/session.h>
 
24
#include <drizzled/connect.h>
 
25
#include <string>
 
26
using namespace std;
 
27
 
 
28
static bool isEnabled= true;
 
29
static bool init_dummy(void) {return 0;}
 
30
 
 
31
/*
 
32
  Simple scheduler that use the main thread to handle the request
 
33
 
 
34
  NOTES
 
35
  This is only used for debugging, when starting mysqld with
 
36
  --thread-handling=no-threads or --one-thread
 
37
 
 
38
  When we enter this function, LOCK_thread_count is hold!
 
39
*/
 
40
 
 
41
void handle_connection_in_main_thread(Session *session)
 
42
{
 
43
  safe_mutex_assert_owner(&LOCK_thread_count);
 
44
  (void) pthread_mutex_unlock(&LOCK_thread_count);
 
45
  handle_one_connection((void*) session);
 
46
}
 
47
 
 
48
 
 
49
/*
 
50
  End connection, in case when we are using 'no-threads'
 
51
*/
 
52
 
 
53
static bool end_thread(Session *session, bool)
 
54
{
 
55
  unlink_session(session);   /* locks LOCK_thread_count and deletes session */
 
56
  pthread_mutex_unlock(&LOCK_thread_count);
 
57
 
 
58
  return true;                                     // Abort handle_one_connection
 
59
}
 
60
 
 
61
static int init(void *p)
 
62
{
 
63
  scheduling_st* func= (scheduling_st *)p;
 
64
 
 
65
  if (isEnabled == false)
 
66
  {
 
67
    func->is_used= false;
 
68
    return 0;
 
69
  }
 
70
  func->is_used= true;
 
71
 
 
72
  func->max_threads= 1;
 
73
  func->add_connection= handle_connection_in_main_thread;
 
74
  func->init_new_connection_thread= init_dummy;
 
75
  func->end_thread= end_thread;
 
76
 
 
77
  return 0;
 
78
}
 
79
 
 
80
static int deinit(void *)
 
81
{
 
82
  return 0;
 
83
}
 
84
 
 
85
static DRIZZLE_SYSVAR_BOOL(enabled, isEnabled,
 
86
                           PLUGIN_VAR_NOCMDARG,
 
87
                           N_("Enable One Thread per Connection Scheduler"),
 
88
                           NULL, /* check func */
 
89
                           NULL, /* update func */
 
90
                           false /* default */);
 
91
 
 
92
static struct st_mysql_sys_var* system_variables[]= {
 
93
  DRIZZLE_SYSVAR(enabled),
 
94
  NULL
 
95
};
 
96
 
 
97
mysql_declare_plugin(single_thread)
 
98
{
 
99
  DRIZZLE_SCHEDULING_PLUGIN,
 
100
  "single_thread",
 
101
  "0.1",
 
102
  "Brian Aker",
 
103
  "Single Thread Scheduler",
 
104
  PLUGIN_LICENSE_GPL,
 
105
  init, /* Plugin Init */
 
106
  deinit, /* Plugin Deinit */
 
107
  NULL,   /* status variables */
 
108
  system_variables,   /* system variables */
 
109
  NULL    /* config options */
 
110
}
 
111
mysql_declare_plugin_end;