~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mf_keycaches.c

Removed/replaced DBUG symbols and standardized TRUE/FALSE

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
  the cache.
22
22
*/
23
23
 
24
 
#include <drizzled/global.h>
25
 
#include <mysys/mysys_err.h>
26
 
#include <mysys/my_sys.h>
 
24
#include "my_global.h"
 
25
#include "mysys_err.h"
 
26
#include <my_sys.h>
27
27
#include <keycache.h>
28
 
#include <mysys/hash.h>
29
 
#include <mystrings/m_string.h>
 
28
#include <hash.h>
 
29
#include <m_string.h>
30
30
 
31
31
/*****************************************************************************
32
32
  General functions to handle SAFE_HASH objects.
46
46
 
47
47
typedef struct st_safe_hash_entry
48
48
{
49
 
  unsigned char *key;
50
 
  uint32_t length;
51
 
  unsigned char *data;
 
49
  uchar *key;
 
50
  uint length;
 
51
  uchar *data;
52
52
  struct st_safe_hash_entry *next, **prev;
53
53
} SAFE_HASH_ENTRY;
54
54
 
57
57
{
58
58
  rw_lock_t mutex;
59
59
  HASH hash;
60
 
  unsigned char *default_value;
 
60
  uchar *default_value;
61
61
  SAFE_HASH_ENTRY *root;
62
62
} SAFE_HASH;
63
63
 
70
70
 
71
71
static void safe_hash_entry_free(SAFE_HASH_ENTRY *entry)
72
72
{
73
 
  free((unsigned char*) entry);
74
 
  return;
 
73
  DBUG_ENTER("free_assign_entry");
 
74
  my_free((uchar*) entry, MYF(0));
 
75
  DBUG_VOID_RETURN;
75
76
}
76
77
 
77
78
 
78
79
/* Get key and length for a SAFE_HASH_ENTRY */
79
80
 
80
 
static unsigned char *safe_hash_entry_get(SAFE_HASH_ENTRY *entry, size_t *length,
81
 
                                  bool not_used __attribute__((unused)))
 
81
static uchar *safe_hash_entry_get(SAFE_HASH_ENTRY *entry, size_t *length,
 
82
                                  my_bool not_used __attribute__((unused)))
82
83
{
83
84
  *length=entry->length;
84
 
  return (unsigned char*) entry->key;
 
85
  return (uchar*) entry->key;
85
86
}
86
87
 
87
88
 
103
104
    1  error
104
105
*/
105
106
 
106
 
static bool safe_hash_init(SAFE_HASH *hash, uint32_t elements,
107
 
                              unsigned char *default_value)
 
107
static my_bool safe_hash_init(SAFE_HASH *hash, uint elements,
 
108
                              uchar *default_value)
108
109
{
 
110
  DBUG_ENTER("safe_hash");
109
111
  if (hash_init(&hash->hash, &my_charset_bin, elements,
110
112
                0, 0, (hash_get_key) safe_hash_entry_get,
111
113
                (void (*)(void*)) safe_hash_entry_free, 0))
112
114
  {
113
115
    hash->default_value= 0;
114
 
    return(1);
 
116
    DBUG_RETURN(1);
115
117
  }
116
118
  my_rwlock_init(&hash->mutex, 0);
117
119
  hash->default_value= default_value;
118
120
  hash->root= 0;
119
 
  return(0);
 
121
  DBUG_RETURN(0);
120
122
}
121
123
 
122
124
 
145
147
  Return the value stored for a key or default value if no key
146
148
*/
147
149
 
148
 
static unsigned char *safe_hash_search(SAFE_HASH *hash, const unsigned char *key, uint32_t length)
 
150
static uchar *safe_hash_search(SAFE_HASH *hash, const uchar *key, uint length)
149
151
{
150
 
  unsigned char *result;
 
152
  uchar *result;
 
153
  DBUG_ENTER("safe_hash_search");
151
154
  rw_rdlock(&hash->mutex);
152
155
  result= hash_search(&hash->hash, key, length);
153
156
  rw_unlock(&hash->mutex);
155
158
    result= hash->default_value;
156
159
  else
157
160
    result= ((SAFE_HASH_ENTRY*) result)->data;
158
 
  return(result);
 
161
  DBUG_PRINT("exit",("data: 0x%lx", (long) result));
 
162
  DBUG_RETURN(result);
159
163
}
160
164
 
161
165
 
179
183
    1  error (Can only be EOM). In this case my_message() is called.
180
184
*/
181
185
 
182
 
static bool safe_hash_set(SAFE_HASH *hash, const unsigned char *key, uint32_t length,
183
 
                             unsigned char *data)
 
186
static my_bool safe_hash_set(SAFE_HASH *hash, const uchar *key, uint length,
 
187
                             uchar *data)
184
188
{
185
189
  SAFE_HASH_ENTRY *entry;
186
 
  bool error= 0;
 
190
  my_bool error= 0;
 
191
  DBUG_ENTER("safe_hash_set");
 
192
  DBUG_PRINT("enter",("key: %.*s  data: 0x%lx", length, key, (long) data));
187
193
 
188
194
  rw_wrlock(&hash->mutex);
189
195
  entry= (SAFE_HASH_ENTRY*) hash_search(&hash->hash, key, length);
200
206
    /* unlink entry from list */
201
207
    if ((*entry->prev= entry->next))
202
208
      entry->next->prev= entry->prev;
203
 
    hash_delete(&hash->hash, (unsigned char*) entry);
 
209
    hash_delete(&hash->hash, (uchar*) entry);
204
210
    goto end;
205
211
  }
206
212
  if (entry)
216
222
      error= 1;
217
223
      goto end;
218
224
    }
219
 
    entry->key= (unsigned char*) (entry +1);
220
 
    memcpy(entry->key, key, length);
 
225
    entry->key= (uchar*) (entry +1);
 
226
    memcpy((char*) entry->key, (char*) key, length);
221
227
    entry->length= length;
222
228
    entry->data= data;
223
229
    /* Link entry to list */
225
231
      entry->next->prev= &entry->next;
226
232
    entry->prev= &hash->root;
227
233
    hash->root= entry;
228
 
    if (my_hash_insert(&hash->hash, (unsigned char*) entry))
 
234
    if (my_hash_insert(&hash->hash, (uchar*) entry))
229
235
    {
230
236
      /* This can only happen if hash got out of memory */
231
 
      free((char*) entry);
 
237
      my_free((char*) entry, MYF(0));
232
238
      error= 1;
233
239
      goto end;
234
240
    }
236
242
 
237
243
end:
238
244
  rw_unlock(&hash->mutex);
239
 
  return(error);
 
245
  DBUG_RETURN(error);
240
246
}
241
247
 
242
248
 
255
261
    default value.
256
262
*/
257
263
 
258
 
static void safe_hash_change(SAFE_HASH *hash, unsigned char *old_data, unsigned char *new_data)
 
264
static void safe_hash_change(SAFE_HASH *hash, uchar *old_data, uchar *new_data)
259
265
{
260
266
  SAFE_HASH_ENTRY *entry, *next;
 
267
  DBUG_ENTER("safe_hash_set");
261
268
 
262
269
  rw_wrlock(&hash->mutex);
263
270
 
270
277
      {
271
278
        if ((*entry->prev= entry->next))
272
279
          entry->next->prev= entry->prev;
273
 
        hash_delete(&hash->hash, (unsigned char*) entry);
 
280
        hash_delete(&hash->hash, (uchar*) entry);
274
281
      }
275
282
      else
276
283
        entry->data= new_data;
278
285
  }
279
286
 
280
287
  rw_unlock(&hash->mutex);
281
 
  return;
 
288
  DBUG_VOID_RETURN;
282
289
}
283
290
 
284
291
 
290
297
static SAFE_HASH key_cache_hash;
291
298
 
292
299
 
293
 
bool multi_keycache_init(void)
 
300
my_bool multi_keycache_init(void)
294
301
{
295
 
  return safe_hash_init(&key_cache_hash, 16, (unsigned char*) dflt_key_cache);
 
302
  return safe_hash_init(&key_cache_hash, 16, (uchar*) dflt_key_cache);
296
303
}
297
304
 
298
305
 
307
314
  SYNOPSIS
308
315
    multi_key_cache_search()
309
316
    key                         key to find (usually table path)
310
 
    uint32_t length                     Length of key.
 
317
    uint length                 Length of key.
311
318
 
312
319
  NOTES
313
320
    This function is coded in such a way that we will return the
318
325
    key cache to use
319
326
*/
320
327
 
321
 
KEY_CACHE *multi_key_cache_search(unsigned char *key, uint32_t length)
 
328
KEY_CACHE *multi_key_cache_search(uchar *key, uint length)
322
329
{
323
330
  if (!key_cache_hash.hash.records)
324
331
    return dflt_key_cache;
342
349
*/
343
350
 
344
351
 
345
 
bool multi_key_cache_set(const unsigned char *key, uint32_t length,
 
352
my_bool multi_key_cache_set(const uchar *key, uint length,
346
353
                            KEY_CACHE *key_cache)
347
354
{
348
 
  return safe_hash_set(&key_cache_hash, key, length, (unsigned char*) key_cache);
 
355
  return safe_hash_set(&key_cache_hash, key, length, (uchar*) key_cache);
349
356
}
350
357
 
351
358
 
352
359
void multi_key_cache_change(KEY_CACHE *old_data,
353
360
                            KEY_CACHE *new_data)
354
361
{
355
 
  safe_hash_change(&key_cache_hash, (unsigned char*) old_data, (unsigned char*) new_data);
 
362
  safe_hash_change(&key_cache_hash, (uchar*) old_data, (uchar*) new_data);
356
363
}