1
/******************************************************
2
The simple hash table utility
6
Created 5/20/1997 Heikki Tuuri
7
*******************************************************/
11
#include "hash0hash.ic"
16
/****************************************************************
17
Reserves the mutex for a fold value in a hash table. */
22
hash_table_t* table, /* in: hash table */
23
ulint fold) /* in: fold */
25
mutex_enter(hash_get_mutex(table, fold));
28
/****************************************************************
29
Releases the mutex for a fold value in a hash table. */
34
hash_table_t* table, /* in: hash table */
35
ulint fold) /* in: fold */
37
mutex_exit(hash_get_mutex(table, fold));
40
/****************************************************************
41
Reserves all the mutexes of a hash table, in an ascending order. */
46
hash_table_t* table) /* in: hash table */
50
for (i = 0; i < table->n_mutexes; i++) {
52
mutex_enter(table->mutexes + i);
56
/****************************************************************
57
Releases all the mutexes of a hash table. */
62
hash_table_t* table) /* in: hash table */
66
for (i = 0; i < table->n_mutexes; i++) {
68
mutex_exit(table->mutexes + i);
72
/*****************************************************************
73
Creates a hash table with >= n array cells. The actual number of cells is
74
chosen to be a prime number slightly bigger than n. */
79
/* out, own: created table */
80
ulint n) /* in: number of array cells */
86
prime = ut_find_prime(n);
88
table = mem_alloc(sizeof(hash_table_t));
90
array = ut_malloc(sizeof(hash_cell_t) * prime);
93
table->adaptive = FALSE;
94
#endif /* UNIV_DEBUG */
96
table->n_cells = prime;
98
table->mutexes = NULL;
101
table->magic_n = HASH_TABLE_MAGIC_N;
103
/* Initialize the cell array */
104
hash_table_clear(table);
109
/*****************************************************************
110
Frees a hash table. */
115
hash_table_t* table) /* in, own: hash table */
117
ut_a(table->mutexes == NULL);
119
ut_free(table->array);
123
/*****************************************************************
124
Creates a mutex array to protect a hash table. */
127
hash_create_mutexes_func(
128
/*=====================*/
129
hash_table_t* table, /* in: hash table */
130
#ifdef UNIV_SYNC_DEBUG
131
ulint sync_level, /* in: latching order level of the
132
mutexes: used in the debug version */
133
#endif /* UNIV_SYNC_DEBUG */
134
ulint n_mutexes) /* in: number of mutexes, must be a
140
ut_a(ut_is_2pow(n_mutexes));
142
table->mutexes = mem_alloc(n_mutexes * sizeof(mutex_t));
144
for (i = 0; i < n_mutexes; i++) {
145
mutex_create(table->mutexes + i, sync_level);
148
table->n_mutexes = n_mutexes;