1
/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2009 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#ifndef PLUGIN_POOL_OF_THREADS_POOL_OF_THREADS_H
21
#define PLUGIN_POOL_OF_THREADS_POOL_OF_THREADS_H
23
#include <drizzled/gettext.h>
24
#include <drizzled/error.h>
25
#include <drizzled/plugin/scheduler.h>
26
#include <drizzled/sql_parse.h>
27
#include <drizzled/session.h>
28
#include <drizzled/plugin/client.h>
29
#include "session_scheduler.h"
32
#include <boost/unordered_set.hpp>
38
* Derived class for pool of threads scheduler.
40
class PoolOfThreadsScheduler: public drizzled::plugin::Scheduler
45
boost::mutex LOCK_session_add; /* protects sessions_need_adding */
46
boost::mutex LOCK_session_kill; /* protects sessions_to_be_killed */
48
* LOCK_event_loop protects the non-thread safe libevent calls (event_add
49
* and event_del) and sessions_need_processing and sessions_waiting_for_io.
51
boost::mutex LOCK_event_loop;
53
std::queue<drizzled::Session *> sessions_need_adding; /* queue of sessions to add to libevent queue */
54
std::queue<drizzled::Session *> sessions_to_be_killed; /* queue of sessions to be killed */
55
std::queue<drizzled::Session *> sessions_need_processing; /* queue of sessions that needs some processing */
57
* Collection of sessions with added events
59
* This should really be a collection of unordered Sessions. No one is more
60
* promising to encounter an io event earlier than another; so no order
63
boost::unordered_set<drizzled::Session *> sessions_waiting_for_io;
66
PoolOfThreadsScheduler(const char *name_arg);
67
~PoolOfThreadsScheduler();
71
* Notify the thread pool about a new connection
73
* @param[in] the newly connected session
76
* True if there is an error.
78
bool addSession(drizzled::Session *session);
83
* Signal a waiting connection it's time to die.
86
* This function will signal libevent the Session should be killed.
88
* @param[in] session The connection to kill
90
void killSession(drizzled::Session *session);
94
* Create all threads for the thread pool
97
* After threads are created we wait until all threads has signaled that
98
* they have started before we return
101
* @retval 1 We got an error creating the thread pool. In this case we will abort all created threads.
103
bool libevent_init(void);
105
void doIO(session_scheduler *sched);
106
void killSession(int Fd);
107
void addSession(int Fd);
109
void sessionAddToQueue(session_scheduler *sched);
114
#endif /* PLUGIN_POOL_OF_THREADS_POOL_OF_THREADS_H */