~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/xid.cc

  • Committer: Brian Aker
  • Date: 2009-01-06 23:40:50 UTC
  • mfrom: (642.1.69 drizzle-clean-code)
  • Revision ID: brian@tangent.org-20090106234050-w01lo5f4r3q62nik
Finished merge for Lee

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
#include <stdint.h>
21
22
#include <string.h>
22
 
 
23
 
#include <drizzled/my_hash.h>
24
23
#include <drizzled/xid.h>
25
 
#include "drizzled/internal/my_pthread.h"
26
 
#include "drizzled/charset.h"
27
 
#include "drizzled/global_charset_info.h"
28
 
#include "drizzled/charset_info.h"
29
24
 
30
 
namespace drizzled
31
 
{
 
25
XID::XID()
 
26
{}
32
27
 
33
28
bool XID::eq(XID *xid)
34
29
{
111
106
{
112
107
  return sizeof(gtrid_length)+sizeof(bqual_length)+gtrid_length+bqual_length;
113
108
}
114
 
 
115
 
/***************************************************************************
116
 
  Handling of XA id cacheing
117
 
***************************************************************************/
118
 
pthread_mutex_t LOCK_xid_cache;
119
 
HASH xid_cache;
120
 
 
121
 
unsigned char *xid_get_hash_key(const unsigned char *, size_t *, bool);
122
 
void xid_free_hash(void *);
123
 
 
124
 
unsigned char *xid_get_hash_key(const unsigned char *ptr, size_t *length,
125
 
                        bool )
126
 
{
127
 
  *length=((XID_STATE*)ptr)->xid.key_length();
128
 
  return ((XID_STATE*)ptr)->xid.key();
129
 
}
130
 
 
131
 
void xid_free_hash(void *ptr)
132
 
{
133
 
  XID_STATE *state= (XID_STATE *)ptr;
134
 
  if (state->in_session == false)
135
 
    delete state;
136
 
}
137
 
 
138
 
bool xid_cache_init()
139
 
{
140
 
  pthread_mutex_init(&LOCK_xid_cache, MY_MUTEX_INIT_FAST);
141
 
  return hash_init(&xid_cache, &my_charset_bin, 100, 0, 0,
142
 
                   xid_get_hash_key, xid_free_hash, 0) != 0;
143
 
}
144
 
 
145
 
void xid_cache_free()
146
 
{
147
 
  if (hash_inited(&xid_cache))
148
 
  {
149
 
    hash_free(&xid_cache);
150
 
    pthread_mutex_destroy(&LOCK_xid_cache);
151
 
  }
152
 
}
153
 
 
154
 
XID_STATE *xid_cache_search(XID *xid)
155
 
{
156
 
  pthread_mutex_lock(&LOCK_xid_cache);
157
 
  XID_STATE *res=(XID_STATE *)hash_search(&xid_cache, xid->key(), xid->key_length());
158
 
  pthread_mutex_unlock(&LOCK_xid_cache);
159
 
  return res;
160
 
}
161
 
 
162
 
bool xid_cache_insert(XID *xid, enum xa_states xa_state)
163
 
{
164
 
  XID_STATE *xs;
165
 
  bool res;
166
 
  pthread_mutex_lock(&LOCK_xid_cache);
167
 
  if (hash_search(&xid_cache, xid->key(), xid->key_length()))
168
 
    res= false;
169
 
  else if ((xs = new XID_STATE) == NULL)
170
 
    res= true;
171
 
  else
172
 
  {
173
 
    xs->xa_state=xa_state;
174
 
    xs->xid.set(xid);
175
 
    xs->in_session=0;
176
 
    res= my_hash_insert(&xid_cache, (unsigned char*)xs);
177
 
  }
178
 
  pthread_mutex_unlock(&LOCK_xid_cache);
179
 
  return res;
180
 
}
181
 
 
182
 
bool xid_cache_insert(XID_STATE *xid_state)
183
 
{
184
 
  pthread_mutex_lock(&LOCK_xid_cache);
185
 
  bool res=my_hash_insert(&xid_cache, (unsigned char*)xid_state);
186
 
  pthread_mutex_unlock(&LOCK_xid_cache);
187
 
  return res;
188
 
}
189
 
 
190
 
void xid_cache_delete(XID_STATE *xid_state)
191
 
{
192
 
  pthread_mutex_lock(&LOCK_xid_cache);
193
 
  hash_delete(&xid_cache, (unsigned char *)xid_state);
194
 
  pthread_mutex_unlock(&LOCK_xid_cache);
195
 
}
196
 
 
197
 
} /* namespace drizzled */