~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/internal/my_thr_init.cc

  • Committer: Lee Bieber
  • Date: 2011-04-18 21:48:09 UTC
  • mfrom: (2280.2.3 build)
  • Revision ID: kalebral@gmail.com-20110418214809-dsdfrc8f90a9p2x1
Merge Olaf - code refactor and pruning dead functions

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
bool my_thread_global_init()
 
63
{
 
64
  return 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
bool 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
 
  {
101
 
    return true;
102
 
  }
103
 
  THR_KEY_mysys.reset(tmp);
104
 
 
 
85
    return false;
105
86
  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)
 
87
  THR_KEY_mysys.reset(new st_my_thread_var(++thread_id));
 
88
  return false; // return void
 
89
}
 
90
 
 
91
st_my_thread_var* _my_thread_var()
129
92
{
130
93
  return THR_KEY_mysys.get();
131
94
}