~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/multi_thread/multi_thread.cc

  • Committer: Olaf van der Spek
  • Date: 2011-03-29 12:04:36 UTC
  • mto: (2257.1.1 build) (2276.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 2258.
  • Revision ID: olafvdspek@gmail.com-20110329120436-vozkuer8vqgh027p
Always call assert()

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