~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/scheduling.cc

  • Committer: Monty Taylor
  • Date: 2009-04-10 18:17:59 UTC
  • mto: (992.1.1 mordred)
  • mto: This revision was merged to the branch mainline in revision 990.
  • Revision ID: mordred@inaugust.com-20090410181759-wr58on1xxc9lwzut
Made plugin registration go through Plugin_registry.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include <drizzled/scheduling.h>
22
22
#include <drizzled/gettext.h>
23
23
#include <drizzled/connect.h>
24
 
 
25
 
Scheduler *thread_scheduler= NULL;
 
24
#include "drizzled/plugin_registry.h"
 
25
 
 
26
 
 
27
SchedulerFactory *scheduler_factory= NULL;
26
28
 
27
29
static bool scheduler_inited= false; /* We must insist that only one of these plugins get loaded at a time */
28
30
 
29
31
 
30
32
extern char *opt_scheduler;
31
33
 
32
 
Scheduler &get_thread_scheduler()
33
 
{
34
 
  assert(thread_scheduler != NULL);
35
 
  return *thread_scheduler;
36
 
}
37
 
 
38
 
int scheduling_initializer(st_plugin_int *plugin)
39
 
{
40
 
  if (memcmp(plugin->plugin->name, opt_scheduler, strlen(opt_scheduler)))
41
 
    return 0;
 
34
bool add_scheduler_factory(SchedulerFactory *factory)
 
35
{
 
36
  if (factory->getName() != opt_scheduler)
 
37
    return true;
42
38
 
43
39
  if (scheduler_inited)
44
40
  {
45
41
    fprintf(stderr, "You cannot load more then one scheduler plugin\n");
 
42
    return(1);
 
43
  }
 
44
  scheduler_factory= factory;
 
45
 
 
46
  scheduler_inited= true;
 
47
  return false;
 
48
}
 
49
 
 
50
Scheduler &get_thread_scheduler()
 
51
{
 
52
  assert(scheduler_factory != NULL);
 
53
  Scheduler *sched= (*scheduler_factory)();
 
54
  if (sched == NULL)
 
55
  {
 
56
    errmsg_printf(ERRMSG_LVL_ERROR, _("Scheduler initialization failed."));
46
57
    exit(1);
47
58
  }
 
59
  return *sched;
 
60
}
 
61
 
 
62
int scheduling_initializer(st_plugin_int *plugin)
 
63
{
 
64
 
 
65
  SchedulerFactory *factory= NULL;
48
66
 
49
67
  assert(plugin->plugin->init); /* Find poorly designed plugins */
50
68
 
51
 
  if (plugin->plugin->init((void *)&thread_scheduler))
 
69
  if (plugin->plugin->init((void *)&factory))
52
70
  {
53
71
    /* 
54
72
      TRANSLATORS> The leading word "scheduling" is the name
59
77
      return 1;
60
78
  }
61
79
 
62
 
  scheduler_inited= true;
 
80
  Plugin_registry &registry= Plugin_registry::get_plugin_registry();
 
81
  if (factory != NULL)
 
82
    registry.registerPlugin(factory);
 
83
  
63
84
  /* We populate so we can find which plugin was initialized later on */
64
 
  plugin->data= (void *)thread_scheduler;
 
85
  plugin->data= (void *)factory;
65
86
 
66
87
  return 0;
67
88
 
72
93
  /* We know which one we initialized since its data pointer is filled */
73
94
  if (plugin->plugin->deinit && plugin->data)
74
95
  {
75
 
    if (plugin->plugin->deinit((void *)thread_scheduler))
 
96
    if (plugin->plugin->deinit((void *)plugin->data))
76
97
    {
77
98
      /* TRANSLATORS: The leading word "scheduling" is the name
78
99
         of the plugin api, and so should not be translated. */