~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/single_thread/single_thread.cc

  • Committer: Brian Aker
  • Date: 2009-07-01 02:41:00 UTC
  • mfrom: (1081.1.4 mordred)
  • Revision ID: brian@gaz-20090701024100-nefdy7pnychzpg7h
Merge Monty

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/scheduler.h>
 
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
 
 
27
class Single_thread_scheduler : public Scheduler
 
28
{
 
29
public:
 
30
  Single_thread_scheduler()
 
31
    : Scheduler(1) {}
 
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
};
 
71
 
 
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
 
 
86
SingleThreadFactory *factory= NULL;
 
87
 
 
88
static int init(PluginRegistry &registry)
 
89
{
 
90
  factory= new SingleThreadFactory();
 
91
  registry.add(factory);
 
92
  return 0;
 
93
}
 
94
 
 
95
static int deinit(PluginRegistry &registry)
 
96
{
 
97
  if (factory)
 
98
  {
 
99
    registry.remove(factory);
 
100
    delete factory;
 
101
  }
 
102
  return 0;
 
103
}
 
104
 
 
105
static struct st_mysql_sys_var* system_variables[]= {
 
106
  NULL
 
107
};
 
108
 
 
109
drizzle_declare_plugin(single_thread)
 
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 */
 
119
  system_variables,   /* system variables */
 
120
  NULL    /* config options */
 
121
}
 
122
drizzle_declare_plugin_end;