~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/single_thread/single_thread.cc

  • Committer: Brian Aker
  • Date: 2009-10-01 22:56:26 UTC
  • mto: (1154.1.1 staging)
  • mto: This revision was merged to the branch mainline in revision 1155.
  • Revision ID: brian@gaz-20091001225626-sb1pdykpxlnkheaj
Remove Factory/make scheduler work like everything else.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
15
 
16
 
#include <drizzled/server_includes.h>
17
 
#include <drizzled/gettext.h>
18
 
#include <drizzled/error.h>
19
 
#include <drizzled/plugin/scheduler.h>
20
 
#include <drizzled/sql_parse.h>
21
 
#include <drizzled/session.h>
22
 
#include <string>
 
16
#include <plugin/single_thread/single_thread.h>
23
17
 
24
18
using namespace std;
25
19
using namespace drizzled;
26
20
 
27
 
/**
28
 
 * Simple scheduler that uses the main thread to handle the request. This
29
 
 * should only be used for debugging.
30
 
 */
31
 
class SingleThreadScheduler : public plugin::Scheduler
32
 
{
33
 
public:
34
 
  SingleThreadScheduler() : Scheduler() {}
35
 
 
36
 
  /* When we enter this function, LOCK_thread_count is held! */
37
 
  virtual bool addSession(Session *session)
38
 
  {
39
 
    if (my_thread_init())
40
 
    {
41
 
      session->disconnect(ER_OUT_OF_RESOURCES, true);
42
 
      statistic_increment(aborted_connects, &LOCK_status);
43
 
      return true;
44
 
    }
45
 
 
46
 
    /*
47
 
      This is not the real thread start beginning, but there is not an easy
48
 
      way to find it.
49
 
    */
50
 
    session->thread_stack= (char *)&session;
51
 
 
52
 
    session->run();
53
 
    killSessionNow(session);
54
 
    return false;
55
 
  }
56
 
 
57
 
  virtual void killSessionNow(Session *session)
58
 
  {
59
 
    unlink_session(session);
60
 
    my_thread_end();
61
 
  }
62
 
};
63
 
 
64
 
 
65
 
class SingleThreadFactory : public plugin::SchedulerFactory
66
 
{
67
 
public:
68
 
  SingleThreadFactory() : SchedulerFactory("single_thread") {}
69
 
  ~SingleThreadFactory() { if (scheduler != NULL) delete scheduler; }
70
 
  plugin::Scheduler *operator() ()
71
 
  {
72
 
    if (scheduler == NULL)
73
 
      scheduler= new SingleThreadScheduler();
74
 
    return scheduler;
75
 
  }
76
 
};
77
 
 
78
 
SingleThreadFactory *factory= NULL;
 
21
 
 
22
/* Global's (TBR) */
 
23
static SingleThreadScheduler *scheduler= NULL;
 
24
 
79
25
 
80
26
static int init(drizzled::plugin::Registry &registry)
81
27
{
82
 
  factory= new SingleThreadFactory();
83
 
  registry.add(factory);
 
28
  scheduler= new SingleThreadScheduler("single_thread");
 
29
  registry.add(scheduler);
84
30
  return 0;
85
31
}
86
32
 
87
33
static int deinit(drizzled::plugin::Registry &registry)
88
34
{
89
 
  if (factory)
90
 
  {
91
 
    registry.remove(factory);
92
 
    delete factory;
93
 
  }
 
35
  registry.remove(scheduler);
 
36
  delete scheduler;
 
37
 
94
38
  return 0;
95
39
}
96
40