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 */
88
prime = ut_find_prime(n);
90
table = mem_alloc(sizeof(hash_table_t));
92
array = ut_malloc(sizeof(hash_cell_t) * prime);
94
table->adaptive = FALSE;
96
table->n_cells = prime;
98
table->mutexes = NULL;
101
table->magic_n = HASH_TABLE_MAGIC_N;
103
/* Initialize the cell array */
105
for (i = 0; i < prime; i++) {
107
cell = hash_get_nth_cell(table, i);
114
/*****************************************************************
115
Frees a hash table. */
120
hash_table_t* table) /* in, own: hash table */
122
ut_a(table->mutexes == NULL);
124
ut_free(table->array);
128
/*****************************************************************
129
Creates a mutex array to protect a hash table. */
132
hash_create_mutexes_func(
133
/*=====================*/
134
hash_table_t* table, /* in: hash table */
135
#ifdef UNIV_SYNC_DEBUG
136
ulint sync_level, /* in: latching order level of the
137
mutexes: used in the debug version */
138
#endif /* UNIV_SYNC_DEBUG */
139
ulint n_mutexes) /* in: number of mutexes, must be a
144
ut_a(n_mutexes == ut_2_power_up(n_mutexes));
146
table->mutexes = mem_alloc(n_mutexes * sizeof(mutex_t));
148
for (i = 0; i < n_mutexes; i++) {
149
mutex_create(table->mutexes + i, sync_level);
152
table->n_mutexes = n_mutexes;