~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mf_keycaches.c

  • Committer: Brian Aker
  • Date: 2008-09-04 19:31:00 UTC
  • Revision ID: brian@tangent.org-20080904193100-l849hgghfy4urj43
Changing default character set from this point on.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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);
 
73
  my_free((uchar*) entry, MYF(0));
74
74
  return;
75
75
}
76
76
 
77
77
 
78
78
/* Get key and length for a SAFE_HASH_ENTRY */
79
79
 
80
 
static unsigned char *safe_hash_entry_get(SAFE_HASH_ENTRY *entry, size_t *length,
 
80
static uchar *safe_hash_entry_get(SAFE_HASH_ENTRY *entry, size_t *length,
81
81
                                  bool not_used __attribute__((unused)))
82
82
{
83
83
  *length=entry->length;
84
 
  return (unsigned char*) entry->key;
 
84
  return (uchar*) entry->key;
85
85
}
86
86
 
87
87
 
103
103
    1  error
104
104
*/
105
105
 
106
 
static bool safe_hash_init(SAFE_HASH *hash, uint32_t elements,
107
 
                              unsigned char *default_value)
 
106
static bool safe_hash_init(SAFE_HASH *hash, uint elements,
 
107
                              uchar *default_value)
108
108
{
109
109
  if (hash_init(&hash->hash, &my_charset_bin, elements,
110
110
                0, 0, (hash_get_key) safe_hash_entry_get,
145
145
  Return the value stored for a key or default value if no key
146
146
*/
147
147
 
148
 
static unsigned char *safe_hash_search(SAFE_HASH *hash, const unsigned char *key, uint32_t length)
 
148
static uchar *safe_hash_search(SAFE_HASH *hash, const uchar *key, uint length)
149
149
{
150
 
  unsigned char *result;
 
150
  uchar *result;
151
151
  rw_rdlock(&hash->mutex);
152
152
  result= hash_search(&hash->hash, key, length);
153
153
  rw_unlock(&hash->mutex);
179
179
    1  error (Can only be EOM). In this case my_message() is called.
180
180
*/
181
181
 
182
 
static bool safe_hash_set(SAFE_HASH *hash, const unsigned char *key, uint32_t length,
183
 
                             unsigned char *data)
 
182
static bool safe_hash_set(SAFE_HASH *hash, const uchar *key, uint length,
 
183
                             uchar *data)
184
184
{
185
185
  SAFE_HASH_ENTRY *entry;
186
186
  bool error= 0;
200
200
    /* unlink entry from list */
201
201
    if ((*entry->prev= entry->next))
202
202
      entry->next->prev= entry->prev;
203
 
    hash_delete(&hash->hash, (unsigned char*) entry);
 
203
    hash_delete(&hash->hash, (uchar*) entry);
204
204
    goto end;
205
205
  }
206
206
  if (entry)
216
216
      error= 1;
217
217
      goto end;
218
218
    }
219
 
    entry->key= (unsigned char*) (entry +1);
 
219
    entry->key= (uchar*) (entry +1);
220
220
    memcpy(entry->key, key, length);
221
221
    entry->length= length;
222
222
    entry->data= data;
225
225
      entry->next->prev= &entry->next;
226
226
    entry->prev= &hash->root;
227
227
    hash->root= entry;
228
 
    if (my_hash_insert(&hash->hash, (unsigned char*) entry))
 
228
    if (my_hash_insert(&hash->hash, (uchar*) entry))
229
229
    {
230
230
      /* This can only happen if hash got out of memory */
231
 
      free((char*) entry);
 
231
      my_free((char*) entry, MYF(0));
232
232
      error= 1;
233
233
      goto end;
234
234
    }
255
255
    default value.
256
256
*/
257
257
 
258
 
static void safe_hash_change(SAFE_HASH *hash, unsigned char *old_data, unsigned char *new_data)
 
258
static void safe_hash_change(SAFE_HASH *hash, uchar *old_data, uchar *new_data)
259
259
{
260
260
  SAFE_HASH_ENTRY *entry, *next;
261
261
 
270
270
      {
271
271
        if ((*entry->prev= entry->next))
272
272
          entry->next->prev= entry->prev;
273
 
        hash_delete(&hash->hash, (unsigned char*) entry);
 
273
        hash_delete(&hash->hash, (uchar*) entry);
274
274
      }
275
275
      else
276
276
        entry->data= new_data;
292
292
 
293
293
bool multi_keycache_init(void)
294
294
{
295
 
  return safe_hash_init(&key_cache_hash, 16, (unsigned char*) dflt_key_cache);
 
295
  return safe_hash_init(&key_cache_hash, 16, (uchar*) dflt_key_cache);
296
296
}
297
297
 
298
298
 
307
307
  SYNOPSIS
308
308
    multi_key_cache_search()
309
309
    key                         key to find (usually table path)
310
 
    uint32_t length                     Length of key.
 
310
    uint length                 Length of key.
311
311
 
312
312
  NOTES
313
313
    This function is coded in such a way that we will return the
318
318
    key cache to use
319
319
*/
320
320
 
321
 
KEY_CACHE *multi_key_cache_search(unsigned char *key, uint32_t length)
 
321
KEY_CACHE *multi_key_cache_search(uchar *key, uint length)
322
322
{
323
323
  if (!key_cache_hash.hash.records)
324
324
    return dflt_key_cache;
342
342
*/
343
343
 
344
344
 
345
 
bool multi_key_cache_set(const unsigned char *key, uint32_t length,
 
345
bool multi_key_cache_set(const uchar *key, uint length,
346
346
                            KEY_CACHE *key_cache)
347
347
{
348
 
  return safe_hash_set(&key_cache_hash, key, length, (unsigned char*) key_cache);
 
348
  return safe_hash_set(&key_cache_hash, key, length, (uchar*) key_cache);
349
349
}
350
350
 
351
351
 
352
352
void multi_key_cache_change(KEY_CACHE *old_data,
353
353
                            KEY_CACHE *new_data)
354
354
{
355
 
  safe_hash_change(&key_cache_hash, (unsigned char*) old_data, (unsigned char*) new_data);
 
355
  safe_hash_change(&key_cache_hash, (uchar*) old_data, (uchar*) new_data);
356
356
}