drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
my_thr_init.cc
1/* Copyright (C) 2000 MySQL AB
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 of the License.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11
12 You should have received a copy of the GNU General Public License
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 */
15
16/*
17 Functions to handle initializating and allocationg of all mysys & debug
18 thread variables.
19*/
20
21#include <config.h>
22
23#include <drizzled/internal/my_sys.h>
24#include <drizzled/internal/thread_var.h>
25#include <drizzled/internal/m_string.h>
26
27#include <cstdio>
28#include <signal.h>
29#include <sys/time.h>
30#include <time.h>
31
32#include <boost/thread/thread.hpp>
33#include <boost/thread/mutex.hpp>
34#include <boost/thread/tss.hpp>
35
36namespace drizzled {
37namespace internal {
38
39thread_local_st THR_KEY_mysys;
40boost::mutex THR_LOCK_threads;
41
42static uint64_t thread_id= 0;
43
44/*
45 Allocate thread specific memory for the thread, used by mysys
46
47 SYNOPSIS
48 my_thread_init()
49
50 RETURN
51 0 ok
52 1 Fatal error; mysys/dbug functions can't be used
53*/
54
55void my_thread_init()
56{
57 // We should never see my_thread_init() called twice
58 if (THR_KEY_mysys.get())
59 {
60 abort();
61 }
62 boost::mutex::scoped_lock scopedLock(THR_LOCK_threads);
63 THR_KEY_mysys.reset(new st_my_thread_var(++thread_id));
64}
65
66thread_local_st& my_thread_var2()
67{
68 return THR_KEY_mysys;
69}
70
71} /* namespace internal */
72} /* namespace drizzled */
TODO: Rename this file - func.h is stupid.