Drizzled Public API Documentation

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 
30 #if TIME_WITH_SYS_TIME
31 # include <sys/time.h>
32 # include <time.h>
33 #else
34 # if HAVE_SYS_TIME_H
35 # include <sys/time.h>
36 # else
37 # include <time.h>
38 # endif
39 #endif
40 
41 #include <boost/thread/thread.hpp>
42 #include <boost/thread/mutex.hpp>
43 #include <boost/thread/tss.hpp>
44 
45 namespace drizzled {
46 namespace internal {
47 
48 thread_local_st THR_KEY_mysys;
49 boost::mutex THR_LOCK_threads;
50 
51 static uint64_t thread_id= 0;
52 
53 /*
54  Allocate thread specific memory for the thread, used by mysys
55 
56  SYNOPSIS
57  my_thread_init()
58 
59  RETURN
60  0 ok
61  1 Fatal error; mysys/dbug functions can't be used
62 */
63 
64 void my_thread_init()
65 {
66  // We should never see my_thread_init() called twice
67  if (THR_KEY_mysys.get())
68  {
69  abort();
70  }
71  boost::mutex::scoped_lock scopedLock(THR_LOCK_threads);
72  THR_KEY_mysys.reset(new st_my_thread_var(++thread_id));
73 }
74 
75 thread_local_st& my_thread_var2()
76 {
77  return THR_KEY_mysys;
78 }
79 
80 } /* namespace internal */
81 } /* namespace drizzled */