107
108
return sizeof(gtrid_length)+sizeof(bqual_length)+gtrid_length+bqual_length;
111
/***************************************************************************
112
Handling of XA id cacheing
113
***************************************************************************/
114
pthread_mutex_t LOCK_xid_cache;
117
extern "C" unsigned char *xid_get_hash_key(const unsigned char *, size_t *, bool);
118
extern "C" void xid_free_hash(void *);
120
unsigned char *xid_get_hash_key(const unsigned char *ptr, size_t *length,
123
*length=((XID_STATE*)ptr)->xid.key_length();
124
return ((XID_STATE*)ptr)->xid.key();
127
void xid_free_hash(void *ptr)
129
if (!((XID_STATE*)ptr)->in_session)
130
free((unsigned char*)ptr);
133
bool xid_cache_init()
135
pthread_mutex_init(&LOCK_xid_cache, MY_MUTEX_INIT_FAST);
136
return hash_init(&xid_cache, &my_charset_bin, 100, 0, 0,
137
xid_get_hash_key, xid_free_hash, 0) != 0;
140
void xid_cache_free()
142
if (hash_inited(&xid_cache))
144
hash_free(&xid_cache);
145
pthread_mutex_destroy(&LOCK_xid_cache);
149
XID_STATE *xid_cache_search(XID *xid)
151
pthread_mutex_lock(&LOCK_xid_cache);
152
XID_STATE *res=(XID_STATE *)hash_search(&xid_cache, xid->key(), xid->key_length());
153
pthread_mutex_unlock(&LOCK_xid_cache);
157
bool xid_cache_insert(XID *xid, enum xa_states xa_state)
161
pthread_mutex_lock(&LOCK_xid_cache);
162
if (hash_search(&xid_cache, xid->key(), xid->key_length()))
164
else if (!(xs=(XID_STATE *)malloc(sizeof(*xs))))
168
xs->xa_state=xa_state;
171
res=my_hash_insert(&xid_cache, (unsigned char*)xs);
173
pthread_mutex_unlock(&LOCK_xid_cache);
177
bool xid_cache_insert(XID_STATE *xid_state)
179
pthread_mutex_lock(&LOCK_xid_cache);
180
assert(hash_search(&xid_cache, xid_state->xid.key(),
181
xid_state->xid.key_length())==0);
182
bool res=my_hash_insert(&xid_cache, (unsigned char*)xid_state);
183
pthread_mutex_unlock(&LOCK_xid_cache);
187
void xid_cache_delete(XID_STATE *xid_state)
189
pthread_mutex_lock(&LOCK_xid_cache);
190
hash_delete(&xid_cache, (unsigned char *)xid_state);
191
pthread_mutex_unlock(&LOCK_xid_cache);