~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/scheduling.cc

  • Committer: Brian Aker
  • Date: 2009-03-22 21:27:04 UTC
  • mfrom: (960.2.22 mordred)
  • Revision ID: brian@tangent.org-20090322212704-ysn4mkkjg2u9kv22
Merge Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include <drizzled/server_includes.h>
21
21
#include <drizzled/scheduling.h>
22
22
#include <drizzled/gettext.h>
23
 
#include <drizzled/plugin_scheduling.h>
24
23
#include <drizzled/connect.h>
25
24
 
26
 
scheduling_st thread_scheduler;
 
25
Scheduler *thread_scheduler= NULL;
 
26
 
27
27
static bool scheduler_inited= false; /* We must insist that only one of these plugins get loaded at a time */
28
28
 
29
 
static void post_kill_dummy(Session *) { return; }
30
 
static bool end_thread_dummy(Session *, bool) { return false; }
31
29
 
32
30
extern char *opt_scheduler;
33
31
 
 
32
Scheduler &get_thread_scheduler()
 
33
{
 
34
  assert(thread_scheduler != NULL);
 
35
  return *thread_scheduler;
 
36
}
 
37
 
34
38
int scheduling_initializer(st_plugin_int *plugin)
35
39
{
36
40
  if (memcmp(plugin->plugin->name, opt_scheduler, strlen(opt_scheduler)))
42
46
    exit(1);
43
47
  }
44
48
 
45
 
  memset(&thread_scheduler, 0, sizeof(scheduling_st));
46
 
 
47
49
  assert(plugin->plugin->init); /* Find poorly designed plugins */
48
 
  if (plugin->plugin->init)
 
50
 
 
51
  if (plugin->plugin->init((void *)&thread_scheduler))
49
52
  {
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
 
    }
 
53
    /* 
 
54
      TRANSLATORS> The leading word "scheduling" is the name
 
55
      of the plugin api, and so should not be translated. 
 
56
    */
 
57
    errmsg_printf(ERRMSG_LVL_ERROR, _("scheduling plugin '%s' init() failed"),
 
58
                        plugin->name.str);
 
59
      return 1;
65
60
  }
66
61
 
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
62
  scheduler_inited= true;
75
63
  /* We populate so we can find which plugin was initialized later on */
76
 
  plugin->data= (void *)&thread_scheduler;
 
64
  plugin->data= (void *)thread_scheduler;
77
65
  plugin->state= PLUGIN_IS_READY;
78
66
 
79
67
  return 0;
80
68
 
81
 
err:
82
 
 
83
 
  return 1;
84
69
}
85
70
 
86
71
int scheduling_finalizer(st_plugin_int *plugin)
88
73
  /* We know which one we initialized since its data pointer is filled */
89
74
  if (plugin->plugin->deinit && plugin->data)
90
75
  {
91
 
    if (plugin->plugin->deinit((void *)&thread_scheduler))
 
76
    if (plugin->plugin->deinit((void *)thread_scheduler))
92
77
    {
93
78
      /* TRANSLATORS: The leading word "scheduling" is the name
94
79
         of the plugin api, and so should not be translated. */
95
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("scheduling plugin '%s' deinit() failed"),
 
80
      errmsg_printf(ERRMSG_LVL_ERROR,
 
81
                    _("scheduling plugin '%s' deinit() failed"),
96
82
                    plugin->name.str);
97
83
    }
98
84
  }