~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/xid.cc

Merge Stewart's dead code removal

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
 
20
#include <drizzled/global.h>
21
21
#include <string.h>
22
22
 
23
 
#include <drizzled/my_hash.h>
 
23
#include <mysys/hash.h>
24
24
#include <drizzled/xid.h>
25
 
#include "drizzled/charset.h"
26
 
#include "drizzled/global_charset_info.h"
27
 
#include "drizzled/charset_info.h"
28
 
 
29
 
#include <boost/thread/mutex.hpp>
30
 
 
31
 
namespace drizzled
32
 
{
 
25
 
 
26
XID::XID()
 
27
{}
33
28
 
34
29
bool XID::eq(XID *xid)
35
30
{
116
111
/***************************************************************************
117
112
  Handling of XA id cacheing
118
113
***************************************************************************/
119
 
boost::mutex LOCK_xid_cache;
 
114
pthread_mutex_t LOCK_xid_cache;
120
115
HASH xid_cache;
121
116
 
122
 
unsigned char *xid_get_hash_key(const unsigned char *, size_t *, bool);
123
 
void xid_free_hash(void *);
 
117
extern "C" unsigned char *xid_get_hash_key(const unsigned char *, size_t *, bool);
 
118
extern "C" void xid_free_hash(void *);
124
119
 
125
120
unsigned char *xid_get_hash_key(const unsigned char *ptr, size_t *length,
126
121
                        bool )
138
133
 
139
134
bool xid_cache_init()
140
135
{
 
136
  pthread_mutex_init(&LOCK_xid_cache, MY_MUTEX_INIT_FAST);
141
137
  return hash_init(&xid_cache, &my_charset_bin, 100, 0, 0,
142
138
                   xid_get_hash_key, xid_free_hash, 0) != 0;
143
139
}
147
143
  if (hash_inited(&xid_cache))
148
144
  {
149
145
    hash_free(&xid_cache);
 
146
    pthread_mutex_destroy(&LOCK_xid_cache);
150
147
  }
151
148
}
152
149
 
153
150
XID_STATE *xid_cache_search(XID *xid)
154
151
{
155
 
  LOCK_xid_cache.lock();
 
152
  pthread_mutex_lock(&LOCK_xid_cache);
156
153
  XID_STATE *res=(XID_STATE *)hash_search(&xid_cache, xid->key(), xid->key_length());
157
 
  LOCK_xid_cache.unlock();
 
154
  pthread_mutex_unlock(&LOCK_xid_cache);
158
155
  return res;
159
156
}
160
157
 
162
159
{
163
160
  XID_STATE *xs;
164
161
  bool res;
165
 
  LOCK_xid_cache.lock();
 
162
  pthread_mutex_lock(&LOCK_xid_cache);
166
163
  if (hash_search(&xid_cache, xid->key(), xid->key_length()))
167
 
  {
168
164
    res= false;
169
 
  }
170
165
  else if ((xs = new XID_STATE) == NULL)
171
 
  {
172
166
    res= true;
173
 
  }
174
167
  else
175
168
  {
176
169
    xs->xa_state=xa_state;
178
171
    xs->in_session=0;
179
172
    res= my_hash_insert(&xid_cache, (unsigned char*)xs);
180
173
  }
181
 
  LOCK_xid_cache.unlock();
 
174
  pthread_mutex_unlock(&LOCK_xid_cache);
182
175
  return res;
183
176
}
184
177
 
185
178
bool xid_cache_insert(XID_STATE *xid_state)
186
179
{
187
 
  LOCK_xid_cache.lock();
 
180
  pthread_mutex_lock(&LOCK_xid_cache);
188
181
  bool res=my_hash_insert(&xid_cache, (unsigned char*)xid_state);
189
 
  LOCK_xid_cache.unlock();
 
182
  pthread_mutex_unlock(&LOCK_xid_cache);
190
183
  return res;
191
184
}
192
185
 
193
186
void xid_cache_delete(XID_STATE *xid_state)
194
187
{
195
 
  LOCK_xid_cache.lock();
 
188
  pthread_mutex_lock(&LOCK_xid_cache);
196
189
  hash_delete(&xid_cache, (unsigned char *)xid_state);
197
 
  LOCK_xid_cache.unlock();
 
190
  pthread_mutex_unlock(&LOCK_xid_cache);
198
191
}
199
 
 
200
 
} /* namespace drizzled */