23
23
#include <drizzled/plugin_scheduling.h>
24
24
#include <drizzled/connect.h>
26
scheduling_st thread_scheduler;
26
Scheduler *thread_scheduler= NULL;
27
28
static bool scheduler_inited= false; /* We must insist that only one of these plugins get loaded at a time */
29
static void post_kill_dummy(Session *) { return; }
30
static bool end_thread_dummy(Session *, bool) { return false; }
32
31
extern char *opt_scheduler;
33
Scheduler &get_thread_scheduler()
35
assert(thread_scheduler != NULL);
36
return *thread_scheduler;
34
39
int scheduling_initializer(st_plugin_int *plugin)
36
41
if (memcmp(plugin->plugin->name, opt_scheduler, strlen(opt_scheduler)))
45
memset(&thread_scheduler, 0, sizeof(scheduling_st));
47
50
assert(plugin->plugin->init); /* Find poorly designed plugins */
48
if (plugin->plugin->init)
52
if (plugin->plugin->init((void *)&thread_scheduler))
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;
55
if (plugin->plugin->init((void *)&thread_scheduler))
58
TRANSLATORS> The leading word "scheduling" is the name
59
of the plugin api, and so should not be translated.
61
errmsg_printf(ERRMSG_LVL_ERROR, _("scheduling plugin '%s' init() failed"),
55
TRANSLATORS> The leading word "scheduling" is the name
56
of the plugin api, and so should not be translated.
58
errmsg_printf(ERRMSG_LVL_ERROR, _("scheduling plugin '%s' init() failed"),
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);
74
63
scheduler_inited= true;
75
64
/* We populate so we can find which plugin was initialized later on */
76
plugin->data= (void *)&thread_scheduler;
65
plugin->data= (void *)thread_scheduler;
77
66
plugin->state= PLUGIN_IS_READY;
86
72
int scheduling_finalizer(st_plugin_int *plugin)
88
74
/* We know which one we initialized since its data pointer is filled */
89
75
if (plugin->plugin->deinit && plugin->data)
91
if (plugin->plugin->deinit((void *)&thread_scheduler))
77
if (plugin->plugin->deinit((void *)thread_scheduler))
93
79
/* TRANSLATORS: The leading word "scheduling" is the name
94
80
of the plugin api, and so should not be translated. */
95
errmsg_printf(ERRMSG_LVL_ERROR, _("scheduling plugin '%s' deinit() failed"),
81
errmsg_printf(ERRMSG_LVL_ERROR,
82
_("scheduling plugin '%s' deinit() failed"),