~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/single_thread/single_thread.cc

Merged Eric from lp:~eday/drizzle/eday-merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
#include <drizzled/gettext.h>
18
18
#include <drizzled/error.h>
19
19
#include <drizzled/plugin/scheduler.h>
20
 
#include <drizzled/connect.h>
21
20
#include <drizzled/sql_parse.h>
22
21
#include <drizzled/session.h>
23
 
#include <drizzled/connect.h>
24
22
#include <string>
 
23
 
25
24
using namespace std;
 
25
using namespace drizzled;
26
26
 
27
 
class Single_thread_scheduler : public Scheduler
 
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
28
32
{
29
33
public:
30
 
  Single_thread_scheduler()
31
 
    : Scheduler(1) {}
 
34
  SingleThreadScheduler() : Scheduler() {}
32
35
 
33
 
  virtual bool init_new_connection_thread(void) {return 0;}
34
 
  
35
 
  /*
36
 
    Simple scheduler that use the main thread to handle the request
37
 
  
38
 
    NOTES
39
 
    This is only used for debugging, when starting mysqld with
40
 
    --thread-handling=no-threads or --one-thread
41
 
  
42
 
    When we enter this function, LOCK_thread_count is held!
43
 
  */
44
 
  
45
 
  virtual bool add_connection(Session *session)
 
36
  /* When we enter this function, LOCK_thread_count is held! */
 
37
  virtual bool addSession(Session *session)
46
38
  {
47
 
    handle_one_connection((void*) session);
48
 
  
 
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);
49
54
    return false;
50
55
  }
51
 
  
52
 
  
53
 
  /*
54
 
    End connection, in case when we are using 'no-threads'
55
 
  */
56
 
  
57
 
  virtual bool end_thread(Session *session, bool)
58
 
  {
59
 
    unlink_session(session);   /* locks LOCK_thread_count and deletes session */
60
 
  
61
 
    return true;                                     // Abort handle_one_connection
62
 
  }
63
 
  
64
 
  
65
 
  virtual uint32_t count(void)
66
 
  {
67
 
    return 0;
68
 
  }
69
 
  
 
56
 
 
57
  virtual void killSessionNow(Session *session)
 
58
  {
 
59
    unlink_session(session);
 
60
    my_thread_end();
 
61
  }
70
62
};
71
63
 
72
64
 
73
 
class SingleThreadFactory : public SchedulerFactory
 
65
class SingleThreadFactory : public plugin::SchedulerFactory
74
66
{
75
67
public:
76
68
  SingleThreadFactory() : SchedulerFactory("single_thread") {}
77
69
  ~SingleThreadFactory() { if (scheduler != NULL) delete scheduler; }
78
 
  Scheduler *operator() ()
 
70
  plugin::Scheduler *operator() ()
79
71
  {
80
72
    if (scheduler == NULL)
81
 
      scheduler= new Single_thread_scheduler();
 
73
      scheduler= new SingleThreadScheduler();
82
74
    return scheduler;
83
75
  }
84
76
};