20
20
#include <drizzled/module/option_map.h>
21
21
#include <drizzled/errmsg_print.h>
23
#include <boost/thread.hpp>
24
#include <boost/bind.hpp>
23
26
namespace po= boost::program_options;
24
27
using namespace std;
25
28
using namespace drizzled;
35
38
extern size_t my_thread_stack_size;
39
* Function to be run as a thread for each session.
43
extern "C" pthread_handler_t session_thread(void *arg);
48
extern "C" pthread_handler_t session_thread(void *arg)
50
Session *session= static_cast<Session*>(arg);
51
MultiThreadScheduler *sched= static_cast<MultiThreadScheduler*>(session->scheduler);
52
sched->runSession(session);
58
bool MultiThreadScheduler::addSession(Session *session)
60
if (thread_count >= max_threads)
41
void MultiThreadScheduler::runSession(drizzled::Session *session)
43
if (drizzled::internal::my_thread_init())
45
session->disconnect(drizzled::ER_OUT_OF_RESOURCES, true);
46
session->status_var.aborted_connects++;
47
killSessionNow(session);
49
boost::this_thread::at_thread_exit(&internal::my_thread_end);
51
session->thread_stack= (char*) &session;
53
killSessionNow(session);
56
void MultiThreadScheduler::setStackSize()
60
(void) pthread_attr_init(&attr);
62
/* Get the thread stack size that the OS will use and make sure
63
that we update our global variable. */
64
int err= pthread_attr_getstacksize(&attr, &my_thread_stack_size);
65
pthread_attr_destroy(&attr);
69
errmsg_printf(ERRMSG_LVL_ERROR, _("Unable to get thread stack size\n"));
70
my_thread_stack_size= 524288; // At the time of the writing of this code, this was OSX's
73
if (my_thread_stack_size == 0)
75
my_thread_stack_size= 524288; // At the time of the writing of this code, this was OSX's
65
79
* Solaris will return zero for the stack size in a call to
73
87
if (my_thread_stack_size == 0)
74
89
my_thread_stack_size= 2 * 1024 * 1024;
77
/* Thread stack size of zero means just use the OS default */
78
if (my_thread_stack_size != 0)
80
int err= pthread_attr_setstacksize(&attr, my_thread_stack_size);
84
errmsg_printf(ERRMSG_LVL_ERROR,
85
_("Unable to set thread stack size to %" PRId64 "\n"),
86
static_cast<uint64_t>(my_thread_stack_size));
92
/* Get the thread stack size that the OS will use and make sure
93
that we update our global variable. */
94
int err= pthread_attr_getstacksize(&attr, &my_thread_stack_size);
98
errmsg_printf(ERRMSG_LVL_ERROR, _("Unable to get thread stack size\n"));
94
bool MultiThreadScheduler::addSession(Session *session)
96
if (thread_count >= max_threads)
103
99
thread_count.increment();
105
if (pthread_create(&session->real_id, &attr, session_thread,
106
static_cast<void*>(session)))
101
boost::thread new_thread(boost::bind(&MultiThreadScheduler::runSession, this, session));
103
if (not new_thread.joinable())
108
105
thread_count.decrement();
118
115
/* Locks LOCK_thread_count and deletes session */
119
116
Session::unlink(session);
120
117
thread_count.decrement();
121
internal::my_thread_end();
123
/* We should never reach this point. */
126
120
MultiThreadScheduler::~MultiThreadScheduler()