~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/pool_of_threads/pool_of_threads.h

  • Committer: Brian Aker
  • Date: 2009-10-01 22:56:26 UTC
  • mto: (1154.1.1 staging)
  • mto: This revision was merged to the branch mainline in revision 1155.
  • Revision ID: brian@gaz-20091001225626-sb1pdykpxlnkheaj
Remove Factory/make scheduler work like everything else.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
3
 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
4
 *
 
5
 * Copyright (C) 2009 Sun Microsystems
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation; version 2 of the License.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 
19
 */
 
20
 
 
21
#include <drizzled/server_includes.h>
 
22
#include <drizzled/gettext.h>
 
23
#include <drizzled/error.h>
 
24
#include <drizzled/plugin/scheduler.h>
 
25
#include <drizzled/sql_parse.h>
 
26
#include <drizzled/session.h>
 
27
#include <drizzled/plugin/client.h>
 
28
#include "session_scheduler.h"
 
29
#include <string>
 
30
#include <queue>
 
31
#include <set>
 
32
#include <event.h>
 
33
 
 
34
 
 
35
/**
 
36
 * @brief 
 
37
 *  Derived class for pool of threads scheduler.
 
38
 */
 
39
class PoolOfThreadsScheduler: public drizzled::plugin::Scheduler
 
40
{
 
41
private:
 
42
  pthread_attr_t attr;
 
43
 
 
44
public:
 
45
  PoolOfThreadsScheduler(const char *name_arg): 
 
46
    Scheduler(name_arg)
 
47
  {
 
48
    struct sched_param tmp_sched_param;
 
49
 
 
50
    memset(&tmp_sched_param, 0, sizeof(struct sched_param));
 
51
    /* Setup attribute parameter for session threads. */
 
52
    (void) pthread_attr_init(&attr);
 
53
    (void) pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
 
54
    pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
 
55
 
 
56
    tmp_sched_param.sched_priority= WAIT_PRIOR;
 
57
    (void) pthread_attr_setschedparam(&attr, &tmp_sched_param);
 
58
  }
 
59
 
 
60
  ~PoolOfThreadsScheduler();
 
61
 
 
62
  /**
 
63
   * @brief 
 
64
   *  Notify the thread pool about a new connection
 
65
   *
 
66
   * @param[in] the newly connected session 
 
67
   *
 
68
   * @return 
 
69
   *  True if there is an error.
 
70
   */
 
71
  bool addSession(Session *session);
 
72
  
 
73
  
 
74
  /**
 
75
   * @brief
 
76
   *  Signal a waiting connection it's time to die.
 
77
   *
 
78
   * @details 
 
79
   *  This function will signal libevent the Session should be killed.
 
80
   *
 
81
   * @param[in]  session The connection to kill
 
82
   */
 
83
  void killSession(Session *session);
 
84
 
 
85
  /**
 
86
   * @brief
 
87
   *  Create all threads for the thread pool
 
88
   *
 
89
   * @details
 
90
   *  After threads are created we wait until all threads has signaled that
 
91
   *  they have started before we return
 
92
   *
 
93
   * @retval 0 Ok
 
94
   * @retval 1 We got an error creating the thread pool. In this case we will abort all created threads.
 
95
   */
 
96
  bool libevent_init(void);
 
97
};