~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/multi_thread/multi_thread.cc

  • Committer: Brian Aker
  • Date: 2010-12-25 00:28:49 UTC
  • mto: This revision was merged to the branch mainline in revision 2031.
  • Revision ID: brian@tangent.org-20101225002849-g73mg6ihulajis0o
First pass in refactoring of the name of my_decimal.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
15
 
16
16
#include "config.h"
17
 
 
18
 
#include <iostream>
19
 
 
20
 
#include <drizzled/pthread_globals.h>
 
17
#include <plugin/multi_thread/multi_thread.h>
 
18
#include "drizzled/pthread_globals.h"
 
19
#include <boost/program_options.hpp>
21
20
#include <drizzled/module/option_map.h>
22
21
#include <drizzled/errmsg_print.h>
23
 
#include <drizzled/session.h>
24
 
#include <drizzled/session/cache.h>
25
 
#include <drizzled/abort_exception.h>
26
 
#include <drizzled/transaction_services.h>
27
 
#include <drizzled/gettext.h>
 
22
#include "drizzled/session.h"
 
23
#include "drizzled/session/cache.h"
28
24
 
29
25
#include <boost/thread.hpp>
30
26
#include <boost/bind.hpp>
31
 
#include <boost/program_options.hpp>
32
 
 
33
 
#include "multi_thread.h"
34
27
 
35
28
namespace po= boost::program_options;
36
29
using namespace std;
51
44
{
52
45
  char stack_dummy;
53
46
  boost::this_thread::disable_interruption disable_by_default;
54
 
 
55
47
  Session::shared_ptr session(session::Cache::singleton().find(id));
56
48
 
57
 
  try
58
 
  {
59
 
 
60
 
    if (not session)
61
 
    {
62
 
      std::cerr << _("Session killed before thread could execute") << endl;
63
 
      return;
64
 
    }
65
 
    session->pushInterrupt(&disable_by_default);
66
 
 
67
 
    if (drizzled::internal::my_thread_init())
68
 
    {
69
 
      session->disconnect(drizzled::ER_OUT_OF_RESOURCES);
70
 
      session->status_var.aborted_connects++;
71
 
    }
72
 
    else
73
 
    {
74
 
      boost::this_thread::at_thread_exit(&internal::my_thread_end);
75
 
 
76
 
      session->thread_stack= (char*) &stack_dummy;
77
 
      session->run();
78
 
    }
79
 
 
80
 
    killSessionNow(session);
81
 
  }
82
 
  catch (abort_exception& ex)
83
 
  {
84
 
    cout << _("Drizzle has receieved an abort event.") << endl;
85
 
    cout << _("In Function: ") << *::boost::get_error_info<boost::throw_function>(ex) << endl;
86
 
    cout << _("In File: ") << *::boost::get_error_info<boost::throw_file>(ex) << endl;
87
 
    cout << _("On Line: ") << *::boost::get_error_info<boost::throw_line>(ex) << endl;
88
 
 
89
 
    TransactionServices::singleton().sendShutdownEvent(*session.get());
90
 
  }
 
49
  if (not session)
 
50
  {
 
51
    std::cerr << "Session killed before thread could execute\n";
 
52
    return;
 
53
  }
 
54
  session->pushInterrupt(&disable_by_default);
 
55
 
 
56
  if (drizzled::internal::my_thread_init())
 
57
  {
 
58
    session->disconnect(drizzled::ER_OUT_OF_RESOURCES);
 
59
    session->status_var.aborted_connects++;
 
60
  }
 
61
  else
 
62
  {
 
63
    boost::this_thread::at_thread_exit(&internal::my_thread_end);
 
64
 
 
65
    session->thread_stack= (char*) &stack_dummy;
 
66
    session->run();
 
67
  }
 
68
 
 
69
  killSessionNow(session);
91
70
  // @todo remove hard spin by disconnection the session first from the
92
71
  // thread.
93
72
  while (not session.unique()) {}
106
85
 
107
86
  if (err != 0)
108
87
  {
109
 
    errmsg_printf(error::ERROR, _("Unable to get thread stack size"));
 
88
    errmsg_printf(ERRMSG_LVL_ERROR, _("Unable to get thread stack size\n"));
110
89
    my_thread_stack_size= 524288; // At the time of the writing of this code, this was OSX's
111
90
  }
112
91
 
137
116
    return true;
138
117
 
139
118
  thread_count.increment();
140
 
  try
141
 
  {
142
 
    session->getThread().reset(new boost::thread((boost::bind(&MultiThreadScheduler::runSession, this, session->getSessionId()))));
143
 
  }
144
 
  catch (std::exception&)
145
 
  {
146
 
    thread_count.decrement();
147
 
    return true;
148
 
  }
 
119
 
 
120
  session->getThread().reset(new boost::thread((boost::bind(&MultiThreadScheduler::runSession, this, session->getSessionId()))));
149
121
 
150
122
  if (not session->getThread())
151
123
  {
176
148
void MultiThreadScheduler::killSessionNow(Session::shared_ptr &session)
177
149
{
178
150
  killSession(session.get());
179
 
 
180
 
  session->disconnect();
181
 
 
182
151
  /* Locks LOCK_thread_count and deletes session */
183
152
  Session::unlink(session);
184
153
  thread_count.decrement();
208
177
{
209
178
  context("max-threads",
210
179
          po::value<max_threads_constraint>(&max_threads)->default_value(2048),
211
 
          _("Maximum number of user threads available."));
 
180
          N_("Maximum number of user threads available."));
212
181
}
213
182
 
214
183
DRIZZLE_DECLARE_PLUGIN
220
189
  "One Thread Per Session Scheduler",
221
190
  PLUGIN_LICENSE_GPL,
222
191
  init, /* Plugin Init */
223
 
  NULL,   /* depends */
 
192
  NULL,   /* system variables */
224
193
  init_options    /* config options */
225
194
}
226
195
DRIZZLE_DECLARE_PLUGIN_END;