1
by brian
clean slate |
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
|
|
1802.10.2
by Monty Taylor
Update all of the copyright headers to include the correct address. |
14 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
1
by brian
clean slate |
15 |
|
16 |
/*
|
|
17 |
Functions to handle initializating and allocationg of all mysys & debug
|
|
18 |
thread variables.
|
|
19 |
*/
|
|
20 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
21 |
#include "config.h" |
22 |
||
23 |
#include "drizzled/internal/my_sys.h" |
|
1689.2.10
by Brian Aker
Move thread_var out to its own include file. |
24 |
#include "drizzled/internal/thread_var.h" |
1241.9.64
by Monty Taylor
Moved remaining non-public portions of mysys and mystrings to drizzled/internal. |
25 |
#include "drizzled/internal/m_string.h" |
612.2.6
by Monty Taylor
OpenSolaris builds. |
26 |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
27 |
#include <cstdio> |
1
by brian
clean slate |
28 |
#include <signal.h> |
29 |
||
481.1.15
by Monty Taylor
Removed time.h and sys/time.h from global.h. |
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
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
39 |
#endif
|
481.1.15
by Monty Taylor
Removed time.h and sys/time.h from global.h. |
40 |
|
1782
by Brian Aker
This modifies our thread system to be based on boost, and it fixes a |
41 |
#include <boost/thread/thread.hpp> |
42 |
#include <boost/thread/mutex.hpp> |
|
43 |
#include <boost/thread/tss.hpp> |
|
44 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
45 |
namespace drizzled |
46 |
{
|
|
47 |
namespace internal |
|
48 |
{
|
|
49 |
||
1782
by Brian Aker
This modifies our thread system to be based on boost, and it fixes a |
50 |
boost::thread_specific_ptr<st_my_thread_var> THR_KEY_mysys; |
1778
by Brian Aker
Cleanup of thr_init. |
51 |
boost::mutex THR_LOCK_threads; |
1
by brian
clean slate |
52 |
|
53 |
/*
|
|
54 |
initialize thread environment
|
|
55 |
||
56 |
SYNOPSIS
|
|
57 |
my_thread_global_init()
|
|
58 |
||
59 |
RETURN
|
|
60 |
0 ok
|
|
61 |
1 error (Couldn't create THR_KEY_mysys)
|
|
62 |
*/
|
|
63 |
||
146
by Brian Aker
my_bool cleanup. |
64 |
bool my_thread_global_init(void) |
1
by brian
clean slate |
65 |
{
|
66 |
if (my_thread_init()) |
|
67 |
{
|
|
68 |
my_thread_global_end(); /* Clean up */ |
|
69 |
return 1; |
|
70 |
}
|
|
71 |
return 0; |
|
72 |
}
|
|
73 |
||
74 |
||
75 |
void my_thread_global_end(void) |
|
76 |
{
|
|
77 |
}
|
|
78 |
||
1241.9.57
by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined. |
79 |
static uint64_t thread_id= 0; |
1
by brian
clean slate |
80 |
|
81 |
/*
|
|
51.3.28
by Jay Pipes
DBUG entirely removed from server and client |
82 |
Allocate thread specific memory for the thread, used by mysys
|
1
by brian
clean slate |
83 |
|
84 |
SYNOPSIS
|
|
85 |
my_thread_init()
|
|
86 |
||
87 |
RETURN
|
|
88 |
0 ok
|
|
89 |
1 Fatal error; mysys/dbug functions can't be used
|
|
90 |
*/
|
|
91 |
||
146
by Brian Aker
my_bool cleanup. |
92 |
bool my_thread_init(void) |
1
by brian
clean slate |
93 |
{
|
1778
by Brian Aker
Cleanup of thr_init. |
94 |
// We should mever see my_thread_init() called twice
|
1782
by Brian Aker
This modifies our thread system to be based on boost, and it fixes a |
95 |
if (THR_KEY_mysys.get()) |
1778
by Brian Aker
Cleanup of thr_init. |
96 |
return 0; |
97 |
||
1782.3.1
by Brian Aker
Pushes up thread ownership to the modules that create them. |
98 |
st_my_thread_var *tmp= new st_my_thread_var; |
1101.1.27
by Monty Taylor
Fixed the plugin string valgrind leak. |
99 |
if (tmp == NULL) |
1
by brian
clean slate |
100 |
{
|
1782.3.1
by Brian Aker
Pushes up thread ownership to the modules that create them. |
101 |
return true; |
1
by brian
clean slate |
102 |
}
|
1782
by Brian Aker
This modifies our thread system to be based on boost, and it fixes a |
103 |
THR_KEY_mysys.reset(tmp); |
1
by brian
clean slate |
104 |
|
1778
by Brian Aker
Cleanup of thr_init. |
105 |
boost::mutex::scoped_lock scopedLock(THR_LOCK_threads); |
1
by brian
clean slate |
106 |
tmp->id= ++thread_id; |
107 |
||
1782.3.1
by Brian Aker
Pushes up thread ownership to the modules that create them. |
108 |
return false; |
1
by brian
clean slate |
109 |
}
|
110 |
||
111 |
||
112 |
/*
|
|
113 |
Deallocate memory used by the thread for book-keeping
|
|
114 |
||
115 |
SYNOPSIS
|
|
116 |
my_thread_end()
|
|
117 |
||
118 |
NOTE
|
|
119 |
This may be called multiple times for a thread.
|
|
120 |
This happens for example when one calls 'mysql_server_init()'
|
|
121 |
mysql_server_end() and then ends with a mysql_end().
|
|
122 |
*/
|
|
123 |
||
124 |
void my_thread_end(void) |
|
125 |
{
|
|
126 |
}
|
|
127 |
||
128 |
struct st_my_thread_var *_my_thread_var(void) |
|
129 |
{
|
|
1782
by Brian Aker
This modifies our thread system to be based on boost, and it fixes a |
130 |
return THR_KEY_mysys.get(); |
1
by brian
clean slate |
131 |
}
|
132 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
133 |
} /* namespace internal */ |
134 |
} /* namespace drizzled */ |