~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/scheduling.cc

  • Committer: Stewart Smith
  • Date: 2009-06-16 03:02:59 UTC
  • mto: This revision was merged to the branch mainline in revision 1065.
  • Revision ID: stewart@flamingspork.com-20090616030259-tn2thqrajk6cappd
ER_NISAMCHK is unused, mark it as so. Thanks to Paul DuBois for researching this for MySQL.

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 Sun Microsystems
 
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/connect.h>
 
24
#include "drizzled/plugin_registry.h"
 
25
#include "drizzled/registry.h"
 
26
 
 
27
using namespace std;
 
28
 
 
29
SchedulerFactory *scheduler_factory= NULL;
 
30
drizzled::Registry<SchedulerFactory *> all_schedulers;
 
31
 
 
32
bool add_scheduler_factory(SchedulerFactory *factory)
 
33
{
 
34
  if (all_schedulers.count(factory->getName()) != 0)
 
35
  {
 
36
    errmsg_printf(ERRMSG_LVL_ERROR,
 
37
                  _("Attempted to register a scheduler %s, but a scheduler "
 
38
                    "has already been registered with that name.\n"),
 
39
                    factory->getName().c_str());
 
40
    return true;
 
41
  }
 
42
  all_schedulers.add(factory);
 
43
  return false;
 
44
}
 
45
 
 
46
 
 
47
bool remove_scheduler_factory(SchedulerFactory *factory)
 
48
{
 
49
  scheduler_factory= NULL;
 
50
  all_schedulers.remove(factory);
 
51
  return false;
 
52
}
 
53
 
 
54
 
 
55
bool set_scheduler_factory(const string& name)
 
56
{
 
57
   
 
58
  SchedulerFactory *factory= all_schedulers.find(name);
 
59
  if (factory == NULL)
 
60
  {
 
61
    errmsg_printf(ERRMSG_LVL_WARN,
 
62
                  _("Attempted to configure %s as the scheduler, which did "
 
63
                    "not exist.\n"), name.c_str());
 
64
    return true;
 
65
  }
 
66
  scheduler_factory= factory;
 
67
 
 
68
  return false;
 
69
}
 
70
 
 
71
Scheduler &get_thread_scheduler()
 
72
{
 
73
  assert(scheduler_factory != NULL);
 
74
  Scheduler *sched= (*scheduler_factory)();
 
75
  if (sched == NULL)
 
76
  {
 
77
    errmsg_printf(ERRMSG_LVL_ERROR, _("Scheduler initialization failed.\n"));
 
78
    exit(1);
 
79
  }
 
80
  return *sched;
 
81
}
 
82