~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
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
21
#include <config.h>
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
22
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
23
#include <drizzled/internal/my_sys.h>
24
#include <drizzled/internal/thread_var.h>
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
2280.1.5 by Olaf van der Spek
Refactor
45
namespace drizzled {
46
namespace internal {
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
47
1782 by Brian Aker
This modifies our thread system to be based on boost, and it fixes a
48
boost::thread_specific_ptr<st_my_thread_var> THR_KEY_mysys;
1778 by Brian Aker
Cleanup of thr_init.
49
boost::mutex THR_LOCK_threads;
1 by brian
clean slate
50
51
/*
52
  initialize thread environment
53
54
  SYNOPSIS
55
    my_thread_global_init()
56
57
  RETURN
58
    0  ok
59
    1  error (Couldn't create THR_KEY_mysys)
60
*/
61
2281.4.5 by Olaf van der Spek
Prune & refactor
62
void my_thread_global_init()
2280.1.5 by Olaf van der Spek
Refactor
63
{
2281.4.5 by Olaf van der Spek
Prune & refactor
64
  my_thread_init();
2280.1.5 by Olaf van der Spek
Refactor
65
}
66
1 by brian
clean slate
67
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
68
static uint64_t thread_id= 0;
1 by brian
clean slate
69
70
/*
51.3.28 by Jay Pipes
DBUG entirely removed from server and client
71
  Allocate thread specific memory for the thread, used by mysys
1 by brian
clean slate
72
73
  SYNOPSIS
74
    my_thread_init()
75
76
  RETURN
77
    0  ok
78
    1  Fatal error; mysys/dbug functions can't be used
79
*/
80
2281.4.5 by Olaf van der Spek
Prune & refactor
81
void my_thread_init()
1 by brian
clean slate
82
{
1778 by Brian Aker
Cleanup of thr_init.
83
  // 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
84
  if (THR_KEY_mysys.get())
2289 by Brian Aker
Prune + abort() if programmer mistake.
85
  {
86
    abort();
87
  }
1778 by Brian Aker
Cleanup of thr_init.
88
  boost::mutex::scoped_lock scopedLock(THR_LOCK_threads);
2280.1.6 by Olaf van der Spek
Refactor
89
  THR_KEY_mysys.reset(new st_my_thread_var(++thread_id));
1 by brian
clean slate
90
}
91
2280.1.7 by Olaf van der Spek
Prune
92
st_my_thread_var* _my_thread_var()
1 by brian
clean slate
93
{
1782 by Brian Aker
This modifies our thread system to be based on boost, and it fixes a
94
  return THR_KEY_mysys.get();
1 by brian
clean slate
95
}
96
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
97
} /* namespace internal */
98
} /* namespace drizzled */