~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/multi_thread/multi_thread.h

pandora-build v0.71. Added check for avahi.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
  You should have received a copy of the GNU General Public License
13
13
  along with this program; if not, write to the Free Software
14
 
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
14
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
#ifndef PLUGIN_MULTI_THREAD_MULTI_THREAD_H
17
17
#define PLUGIN_MULTI_THREAD_MULTI_THREAD_H
20
20
#include <drizzled/gettext.h>
21
21
#include <drizzled/error.h>
22
22
#include <drizzled/plugin/scheduler.h>
23
 
#include "drizzled/internal/my_sys.h"
24
23
#include <drizzled/sql_parse.h>
 
24
#include <drizzled/session.h>
25
25
#include <string>
26
26
 
27
 
namespace drizzled {
28
 
class Session;
29
 
}
30
 
 
31
 
namespace multi_thread {
32
 
 
33
27
class MultiThreadScheduler: public drizzled::plugin::Scheduler
34
28
{
35
29
private:
36
30
  drizzled::atomic<uint32_t> thread_count;
 
31
  pthread_attr_t attr;
37
32
 
38
33
public:
39
34
  MultiThreadScheduler(const char *name_arg): 
40
35
    Scheduler(name_arg)
41
36
  {
42
 
    setStackSize();
 
37
    struct sched_param tmp_sched_param;
 
38
 
 
39
    memset(&tmp_sched_param, 0, sizeof(struct sched_param));
 
40
 
 
41
    /* Setup attribute parameter for session threads. */
 
42
    (void) pthread_attr_init(&attr);
 
43
    (void) pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
 
44
    pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
 
45
 
 
46
    tmp_sched_param.sched_priority= WAIT_PRIOR;
 
47
    (void) pthread_attr_setschedparam(&attr, &tmp_sched_param);
 
48
 
43
49
    thread_count= 0;
44
50
  }
45
51
 
46
52
  ~MultiThreadScheduler();
47
 
  bool addSession(drizzled::Session::shared_ptr &session);
48
 
  void killSessionNow(drizzled::Session::shared_ptr &session);
49
 
  void killSession(drizzled::Session*);
 
53
  bool addSession(Session *session);
 
54
  void killSessionNow(Session *session);
50
55
  
51
 
  void runSession(drizzled::session_id_t);
52
 
private:
53
 
  void setStackSize();
 
56
  void runSession(Session *session)
 
57
  {
 
58
    if (my_thread_init())
 
59
    {
 
60
      session->disconnect(ER_OUT_OF_RESOURCES, true);
 
61
      statistic_increment(aborted_connects, &LOCK_status);
 
62
      killSessionNow(session);
 
63
    }
 
64
 
 
65
    session->thread_stack= (char*) &session;
 
66
    session->run();
 
67
    killSessionNow(session);
 
68
  }
54
69
};
55
70
 
56
 
} // namespace multi_thread
57
 
 
58
71
#endif /* PLUGIN_MULTI_THREAD_MULTI_THREAD_H */