~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/internal/my_thr_init.cc

  • Committer: Olaf van der Spek
  • Date: 2011-07-05 13:16:34 UTC
  • mto: This revision was merged to the branch mainline in revision 2384.
  • Revision ID: olafvdspek@gmail.com-20110705131634-f7g1fjro5slibmdj
Add data_ref.h
Use str_ref for append_identifier

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
  thread variables.
19
19
*/
20
20
 
21
 
#include "config.h"
 
21
#include <config.h>
22
22
 
23
 
#include "drizzled/internal/my_sys.h"
24
 
#include "drizzled/internal/thread_var.h"
25
 
#include "drizzled/internal/m_string.h"
 
23
#include <drizzled/internal/my_sys.h>
 
24
#include <drizzled/internal/thread_var.h>
 
25
#include <drizzled/internal/m_string.h>
26
26
 
27
27
#include <cstdio>
28
28
#include <signal.h>
42
42
#include <boost/thread/mutex.hpp>
43
43
#include <boost/thread/tss.hpp>
44
44
 
45
 
namespace drizzled
46
 
{
47
 
namespace internal
48
 
{
 
45
namespace drizzled {
 
46
namespace internal {
49
47
 
50
48
boost::thread_specific_ptr<st_my_thread_var> THR_KEY_mysys;
51
49
boost::mutex THR_LOCK_threads;
61
59
    1  error (Couldn't create THR_KEY_mysys)
62
60
*/
63
61
 
64
 
bool my_thread_global_init(void)
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
 
}
 
62
void my_thread_global_init()
 
63
{
 
64
  my_thread_init();
 
65
}
 
66
 
78
67
 
79
68
static uint64_t thread_id= 0;
80
69
 
89
78
    1  Fatal error; mysys/dbug functions can't be used
90
79
*/
91
80
 
92
 
bool my_thread_init(void)
 
81
void my_thread_init()
93
82
{
94
83
  // We should mever see my_thread_init()  called twice
95
84
  if (THR_KEY_mysys.get())
96
 
    return 0;
97
 
 
98
 
  st_my_thread_var *tmp= new st_my_thread_var;
99
 
  if (tmp == NULL)
100
85
  {
101
 
    return true;
 
86
    abort();
102
87
  }
103
 
  THR_KEY_mysys.reset(tmp);
104
 
 
105
88
  boost::mutex::scoped_lock scopedLock(THR_LOCK_threads);
106
 
  tmp->id= ++thread_id;
107
 
 
108
 
  return false;
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 'server_init()'
121
 
    server_end() and then ends with a end().
122
 
*/
123
 
 
124
 
void my_thread_end(void)
125
 
{
126
 
}
127
 
 
128
 
struct st_my_thread_var *_my_thread_var(void)
 
89
  THR_KEY_mysys.reset(new st_my_thread_var(++thread_id));
 
90
}
 
91
 
 
92
st_my_thread_var* _my_thread_var()
129
93
{
130
94
  return THR_KEY_mysys.get();
131
95
}