~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/single_thread/single_thread.h

  • 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:
 
1
/* Copyright (C) 2009 Sun Microsystems
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
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>
 
23
 
 
24
 
 
25
/**
 
26
 * Simple scheduler that uses the main thread to handle the request. This
 
27
 * should only be used for debugging.
 
28
 */
 
29
class SingleThreadScheduler : public drizzled::plugin::Scheduler
 
30
{
 
31
public:
 
32
  SingleThreadScheduler(const char *name_arg) : 
 
33
    Scheduler(name_arg) {}
 
34
 
 
35
  /* When we enter this function, LOCK_thread_count is held! */
 
36
  virtual bool addSession(Session *session)
 
37
  {
 
38
    if (my_thread_init())
 
39
    {
 
40
      session->disconnect(ER_OUT_OF_RESOURCES, true);
 
41
      statistic_increment(aborted_connects, &LOCK_status);
 
42
      return true;
 
43
    }
 
44
 
 
45
    /*
 
46
      This is not the real thread start beginning, but there is not an easy
 
47
      way to find it.
 
48
    */
 
49
    session->thread_stack= (char *)&session;
 
50
 
 
51
    session->run();
 
52
    killSessionNow(session);
 
53
    return false;
 
54
  }
 
55
 
 
56
  virtual void killSessionNow(Session *session)
 
57
  {
 
58
    unlink_session(session);
 
59
    my_thread_end();
 
60
  }
 
61
};