~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/pool_of_threads/session_scheduler.cc

  • Committer: Brian Aker
  • Date: 2009-01-24 04:31:39 UTC
  • Revision ID: brian@gir-3.local-20090124043139-5cu9wjefszrnyhe0
Refactored all current scheduler to be behind scheduler plugin api.

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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
/*
 
17
  session_scheduler keeps the link between Session and events.
 
18
  It's embedded in the Session class.
 
19
*/
 
20
 
 
21
#include <drizzled/session.h>
 
22
#include <drizzled/gettext.h>
 
23
#include <drizzled/errmsg_print.h>
 
24
#include <event.h>
 
25
/* API for connecting, logging in to a drizzled server */
 
26
#include <drizzled/connect.h>
 
27
#include "session_scheduler.h"
 
28
 
 
29
/* Prototype */
 
30
void libevent_io_callback(int Fd, short Operation, void *ctx);
 
31
bool libevent_should_close_connection(Session* session);
 
32
void libevent_session_add(Session* session);
 
33
 
 
34
session_scheduler::session_scheduler()
 
35
  : logged_in(false), io_event(NULL), thread_attached(false)
 
36
{
 
37
}
 
38
 
 
39
 
 
40
session_scheduler::~session_scheduler()
 
41
{
 
42
  delete io_event;
 
43
}
 
44
 
 
45
 
 
46
session_scheduler::session_scheduler(const session_scheduler&)
 
47
  : logged_in(false), io_event(NULL), thread_attached(false)
 
48
{}
 
49
 
 
50
void session_scheduler::operator=(const session_scheduler&)
 
51
{}
 
52
 
 
53
bool session_scheduler::init(Session *parent_session)
 
54
{
 
55
  io_event= new struct event;
 
56
 
 
57
  if (io_event == NULL)
 
58
  {
 
59
    errmsg_printf(ERRMSG_LVL_ERROR, _("Memory allocation error in session_scheduler::init\n"));
 
60
    return true;
 
61
  }
 
62
  memset(io_event, 0, sizeof(*io_event));
 
63
 
 
64
  event_set(io_event, net_get_sd(&(parent_session->net)), EV_READ,
 
65
            libevent_io_callback, (void*)parent_session);
 
66
 
 
67
  list.data= parent_session;
 
68
 
 
69
  return false;
 
70
}
 
71
 
 
72
 
 
73
/*
 
74
  Attach/associate the connection with the OS thread, for command processing.
 
75
*/
 
76
 
 
77
bool session_scheduler::thread_attach()
 
78
{
 
79
  assert(!thread_attached);
 
80
  Session* session = (Session*)list.data;
 
81
  if (libevent_should_close_connection(session) ||
 
82
      setup_connection_thread_globals(session))
 
83
  {
 
84
    return true;
 
85
  }
 
86
  my_errno= 0;
 
87
  session->mysys_var->abort= 0;
 
88
  thread_attached= true;
 
89
 
 
90
  return false;
 
91
}
 
92
 
 
93
 
 
94
/*
 
95
  Detach/disassociate the connection with the OS thread.
 
96
*/
 
97
 
 
98
void session_scheduler::thread_detach()
 
99
{
 
100
  if (thread_attached)
 
101
  {
 
102
    Session* session = (Session*)list.data;
 
103
    session->mysys_var= NULL;
 
104
    thread_attached= false;
 
105
  }
 
106
}