~drizzle-trunk/drizzle/development

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