~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/scheduling.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:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
 
4
 *  Copyright (C) 2008 Mark Atwood
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
21
 
#include "drizzled/plugin/scheduler.h"
22
 
#include "drizzled/plugin/registry.h"
23
 
 
24
 
#include "drizzled/gettext.h"
25
 
 
26
 
using namespace std;
27
 
 
28
 
namespace drizzled
29
 
{
30
 
 
31
 
vector<plugin::Scheduler *> all_schedulers;
32
 
 
33
 
/* Globals (TBK) */
34
 
static plugin::Scheduler *scheduler= NULL;
35
 
 
36
 
 
37
 
class FindSchedulerByName : public unary_function<plugin::Scheduler *, bool>
38
 
{
39
 
  const string *name;
40
 
public:
41
 
  FindSchedulerByName(const string *name_arg)
42
 
    : name(name_arg) {}
43
 
  result_type operator() (argument_type sched)
44
 
  {
45
 
    return (bool)((name->compare(sched->getName()) == 0));
46
 
  }
47
 
};
48
 
 
49
 
 
50
 
bool plugin::Scheduler::addPlugin(plugin::Scheduler *sched)
51
 
{
52
 
  vector<plugin::Scheduler *>::iterator iter=
53
 
    find_if(all_schedulers.begin(), all_schedulers.end(), 
54
 
            FindSchedulerByName(&sched->getName()));
55
 
 
56
 
  if (iter != all_schedulers.end())
57
 
  {
58
 
    errmsg_printf(ERRMSG_LVL_ERROR,
59
 
                  _("Attempted to register a scheduler %s, but a scheduler "
60
 
                    "has already been registered with that name.\n"),
61
 
                    sched->getName().c_str());
62
 
    return true;
63
 
  }
64
 
 
65
 
  sched->deactivate();
66
 
  all_schedulers.push_back(sched);
67
 
 
68
 
  return false;
69
 
}
70
 
 
71
 
 
72
 
void plugin::Scheduler::removePlugin(plugin::Scheduler *sched)
73
 
{
74
 
  all_schedulers.erase(find(all_schedulers.begin(),
75
 
                            all_schedulers.end(),
76
 
                            sched));
77
 
}
78
 
 
79
 
 
80
 
bool plugin::Scheduler::setPlugin(const string& name)
81
 
{
82
 
  vector<plugin::Scheduler *>::iterator iter=
83
 
    find_if(all_schedulers.begin(), all_schedulers.end(), 
84
 
            FindSchedulerByName(&name));
85
 
 
86
 
  if (iter != all_schedulers.end())
87
 
  {
88
 
    if (scheduler != NULL)
89
 
      scheduler->deactivate();
90
 
    scheduler= *iter;
91
 
    scheduler->activate();
92
 
    return false;
93
 
  }
94
 
 
95
 
  errmsg_printf(ERRMSG_LVL_WARN,
96
 
                _("Attempted to configure %s as the scheduler, which did "
97
 
                  "not exist.\n"), name.c_str());
98
 
  return true;
99
 
}
100
 
 
101
 
 
102
 
plugin::Scheduler *plugin::Scheduler::getScheduler()
103
 
{
104
 
  return scheduler;
105
 
}
106
 
 
107
 
} /* namespace drizzled */
 
20
#include <drizzled/server_includes.h>
 
21
#include <drizzled/scheduling.h>
 
22
#include <drizzled/gettext.h>
 
23
#include <drizzled/scheduler.h>
 
24
 
 
25
extern scheduler_functions thread_scheduler;
 
26
 
 
27
int scheduling_initializer(st_plugin_int *plugin)
 
28
{
 
29
  scheduling_t *p;
 
30
 
 
31
  p= new scheduling_t;
 
32
  if (p == NULL) return 1;
 
33
  memset(p, 0, sizeof(scheduling_t));
 
34
 
 
35
  plugin->data= (void *)p;
 
36
 
 
37
  if (plugin->plugin->init)
 
38
  {
 
39
    if (plugin->plugin->init((void *)&thread_scheduler))
 
40
    {
 
41
      /* 
 
42
        TRANSLATORS> The leading word "scheduling" is the name
 
43
        of the plugin api, and so should not be translated. 
 
44
      */
 
45
      errmsg_printf(ERRMSG_LVL_ERROR, _("scheduling plugin '%s' init() failed"),
 
46
                      plugin->name.str);
 
47
      goto err;
 
48
    }
 
49
  }
 
50
  return 0;
 
51
 
 
52
err:
 
53
  free(p);
 
54
  return 1;
 
55
}
 
56
 
 
57
int scheduling_finalizer(st_plugin_int *plugin)
 
58
{
 
59
  scheduling_t *p= (scheduling_t *) plugin->data;
 
60
 
 
61
  if (plugin->plugin->deinit)
 
62
  {
 
63
    if (plugin->plugin->deinit((void *)p))
 
64
    {
 
65
      /* TRANSLATORS: The leading word "scheduling" is the name
 
66
         of the plugin api, and so should not be translated. */
 
67
      errmsg_printf(ERRMSG_LVL_ERROR, _("scheduling plugin '%s' deinit() failed"),
 
68
                      plugin->name.str);
 
69
    }
 
70
  }
 
71
 
 
72
  if (p) free(p);
 
73
 
 
74
  return 0;
 
75
}