~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/scheduling.cc

  • Committer: Padraig O'Sullivan
  • Date: 2009-03-21 20:26:28 UTC
  • mto: (960.2.5 mordred)
  • mto: This revision was merged to the branch mainline in revision 961.
  • Revision ID: osullivan.padraig@gmail.com-20090321202628-nh6qsi825m4d4av6
Removing the queues.[h,cc] files from the mysys directory. The only place
where they are needed now is in the MyISAM storage engine. Thus, I moved the
files there and updated the files in the MyISAM storage engine
appropriately.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008 Mark Atwood
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; version 2 of the License.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
 
19
 
 
20
#include <drizzled/server_includes.h>
 
21
#include <drizzled/scheduling.h>
 
22
#include <drizzled/gettext.h>
 
23
#include <drizzled/plugin_scheduling.h>
 
24
#include <drizzled/connect.h>
 
25
 
 
26
scheduling_st thread_scheduler;
 
27
static bool scheduler_inited= false; /* We must insist that only one of these plugins get loaded at a time */
 
28
 
 
29
static void post_kill_dummy(Session *) { return; }
 
30
static bool end_thread_dummy(Session *, bool) { return false; }
 
31
 
 
32
extern char *opt_scheduler;
 
33
 
 
34
int scheduling_initializer(st_plugin_int *plugin)
 
35
{
 
36
  if (memcmp(plugin->plugin->name, opt_scheduler, strlen(opt_scheduler)))
 
37
    return 0;
 
38
 
 
39
  if (scheduler_inited)
 
40
  {
 
41
    fprintf(stderr, "You cannot load more then one scheduler plugin\n");
 
42
    exit(1);
 
43
  }
 
44
 
 
45
  memset(&thread_scheduler, 0, sizeof(scheduling_st));
 
46
 
 
47
  assert(plugin->plugin->init); /* Find poorly designed plugins */
 
48
  if (plugin->plugin->init)
 
49
  {
 
50
 
 
51
    thread_scheduler.post_kill_notification= post_kill_dummy;
 
52
    thread_scheduler.end_thread= end_thread_dummy;
 
53
    thread_scheduler.init_new_connection_thread= init_new_connection_handler_thread;
 
54
 
 
55
    if (plugin->plugin->init((void *)&thread_scheduler))
 
56
    {
 
57
      /* 
 
58
        TRANSLATORS> The leading word "scheduling" is the name
 
59
        of the plugin api, and so should not be translated. 
 
60
      */
 
61
      errmsg_printf(ERRMSG_LVL_ERROR, _("scheduling plugin '%s' init() failed"),
 
62
                      plugin->name.str);
 
63
      goto err;
 
64
    }
 
65
  }
 
66
 
 
67
  /* We are going to assert() on any plugin that is not well written. */
 
68
  assert(thread_scheduler.max_threads);
 
69
  assert(thread_scheduler.init_new_connection_thread);
 
70
  assert(thread_scheduler.add_connection);
 
71
  assert(thread_scheduler.post_kill_notification);
 
72
  assert(thread_scheduler.end_thread);
 
73
 
 
74
  scheduler_inited= true;
 
75
  /* We populate so we can find which plugin was initialized later on */
 
76
  plugin->data= (void *)&thread_scheduler;
 
77
  plugin->state= PLUGIN_IS_READY;
 
78
 
 
79
  return 0;
 
80
 
 
81
err:
 
82
 
 
83
  return 1;
 
84
}
 
85
 
 
86
int scheduling_finalizer(st_plugin_int *plugin)
 
87
{
 
88
  /* We know which one we initialized since its data pointer is filled */
 
89
  if (plugin->plugin->deinit && plugin->data)
 
90
  {
 
91
    if (plugin->plugin->deinit((void *)&thread_scheduler))
 
92
    {
 
93
      /* TRANSLATORS: The leading word "scheduling" is the name
 
94
         of the plugin api, and so should not be translated. */
 
95
      errmsg_printf(ERRMSG_LVL_ERROR, _("scheduling plugin '%s' deinit() failed"),
 
96
                    plugin->name.str);
 
97
    }
 
98
  }
 
99
 
 
100
  return 0;
 
101
}