~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-01-24 09:43:35 UTC
  • Revision ID: brian@gir-3.local-20090124094335-6qdtvc35gl5fvivz
Adding in an example singe thread scheduler

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
15
 
16
 
#include "config.h"
17
 
#include <plugin/single_thread/single_thread.h>
18
 
 
 
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>
19
26
using namespace std;
20
 
using namespace drizzled;
21
 
 
22
 
 
23
 
/* Global's (TBR) */
24
 
static SingleThreadScheduler *scheduler= NULL;
25
 
 
26
 
 
27
 
static int init(plugin::Context &context)
28
 
{
29
 
  scheduler= new SingleThreadScheduler("single_thread");
30
 
  context.add(scheduler);
31
 
  return 0;
32
 
}
33
 
 
34
 
DRIZZLE_DECLARE_PLUGIN
35
 
{
36
 
  DRIZZLE_VERSION_ID,
 
27
 
 
28
static bool init_dummy(void) {return 0;}
 
29
 
 
30
/*
 
31
  Simple scheduler that use the main thread to handle the request
 
32
 
 
33
  NOTES
 
34
  This is only used for debugging, when starting mysqld with
 
35
  --thread-handling=no-threads or --one-thread
 
36
 
 
37
  When we enter this function, LOCK_thread_count is hold!
 
38
*/
 
39
 
 
40
void handle_connection_in_main_thread(Session *session)
 
41
{
 
42
  safe_mutex_assert_owner(&LOCK_thread_count);
 
43
  (void) pthread_mutex_unlock(&LOCK_thread_count);
 
44
  handle_one_connection((void*) session);
 
45
}
 
46
 
 
47
 
 
48
/*
 
49
  End connection, in case when we are using 'no-threads'
 
50
*/
 
51
 
 
52
static bool end_thread(Session *, bool)
 
53
{
 
54
  pthread_mutex_unlock(&LOCK_thread_count);
 
55
  return true;                                     // Abort handle_one_connection
 
56
}
 
57
 
 
58
static int init(void *p)
 
59
{
 
60
  scheduler_functions* func= (scheduler_functions *)p;
 
61
 
 
62
  func->max_threads= 1;
 
63
  func->add_connection= handle_connection_in_main_thread;
 
64
  func->init_new_connection_thread= init_dummy;
 
65
  func->end_thread= end_thread;
 
66
 
 
67
  return 0;
 
68
}
 
69
 
 
70
static int deinit(void *)
 
71
{
 
72
  return 0;
 
73
}
 
74
 
 
75
mysql_declare_plugin(single_thread)
 
76
{
 
77
  DRIZZLE_SCHEDULING_PLUGIN,
37
78
  "single_thread",
38
79
  "0.1",
39
80
  "Brian Aker",
40
81
  "Single Thread Scheduler",
41
82
  PLUGIN_LICENSE_GPL,
42
83
  init, /* Plugin Init */
 
84
  deinit, /* Plugin Deinit */
 
85
  NULL,   /* status variables */
43
86
  NULL,   /* system variables */
44
87
  NULL    /* config options */
45
88
}
46
 
DRIZZLE_DECLARE_PLUGIN_END;
 
89
mysql_declare_plugin_end;