23
23
#include <drizzled/session.h>
24
24
#include <drizzled/connect.h>
26
27
using namespace std;
28
pthread_attr_t multi_thread_attrib;
29
29
static uint32_t max_threads;
30
static tbb::atomic<uint32_t> thread_count;
32
static bool add_connection(Session *session)
38
if ((error= pthread_create(&session->real_id, &multi_thread_attrib, handle_one_connection, (void*) session)))
46
End connection, in case when we are using 'no-threads'
49
static bool end_thread(Session *session, bool)
51
unlink_session(session); /* locks LOCK_thread_count and deletes session */
57
return true; // We should never reach this point
60
static uint32_t count_of_threads(void)
31
class Multi_thread_scheduler: public Scheduler
33
tbb::atomic<uint32_t> thread_count;
34
pthread_attr_t multi_thread_attrib;
37
Multi_thread_scheduler(uint32_t threads): Scheduler(threads)
40
/* Parameter for threads created for connections */
41
(void) pthread_attr_init(&multi_thread_attrib);
42
(void) pthread_attr_setdetachstate(&multi_thread_attrib,
43
PTHREAD_CREATE_DETACHED);
44
pthread_attr_setscope(&multi_thread_attrib, PTHREAD_SCOPE_SYSTEM);
46
struct sched_param tmp_sched_param;
48
memset(&tmp_sched_param, 0, sizeof(tmp_sched_param));
49
tmp_sched_param.sched_priority= WAIT_PRIOR;
50
(void)pthread_attr_setschedparam(&multi_thread_attrib, &tmp_sched_param);
54
~Multi_thread_scheduler()
56
(void) pthread_mutex_lock(&LOCK_thread_count);
59
pthread_cond_wait(&COND_thread_count, &LOCK_thread_count);
61
(void) pthread_mutex_unlock(&LOCK_thread_count);
63
pthread_attr_destroy(&multi_thread_attrib);
66
virtual bool add_connection(Session *session)
72
if ((error= pthread_create(&session->real_id, &multi_thread_attrib, handle_one_connection, static_cast<void*>(session))))
80
End connection, in case when we are using 'no-threads'
83
virtual bool end_thread(Session *session, bool)
85
unlink_session(session); /* locks LOCK_thread_count and deletes session */
91
return true; // We should never reach this point
94
virtual uint32_t count(void)
65
100
static int init(void *p)
67
scheduling_st* func= (scheduling_st *)p;
69
func->max_threads= max_threads; /* This will create an upper limit on max connections */
70
func->add_connection= add_connection;
71
func->end_thread= end_thread;
72
func->count= count_of_threads;
74
/* Parameter for threads created for connections */
75
(void) pthread_attr_init(&multi_thread_attrib);
76
(void) pthread_attr_setdetachstate(&multi_thread_attrib,
77
PTHREAD_CREATE_DETACHED);
78
pthread_attr_setscope(&multi_thread_attrib, PTHREAD_SCOPE_SYSTEM);
80
struct sched_param tmp_sched_param;
82
memset(&tmp_sched_param, 0, sizeof(tmp_sched_param));
83
tmp_sched_param.sched_priority= WAIT_PRIOR;
84
(void)pthread_attr_setschedparam(&multi_thread_attrib, &tmp_sched_param);
102
Multi_thread_scheduler** sched= static_cast<Multi_thread_scheduler **>(p);
104
*sched= new Multi_thread_scheduler(max_threads);
90
static int deinit(void *)
109
static int deinit(void *p)
92
(void) pthread_mutex_lock(&LOCK_thread_count);
95
pthread_cond_wait(&COND_thread_count, &LOCK_thread_count);
97
(void) pthread_mutex_unlock(&LOCK_thread_count);
99
pthread_attr_destroy(&multi_thread_attrib);
112
Multi_thread_scheduler *sched= static_cast<Multi_thread_scheduler *>(p);