17
17
*****************************************************************************/
19
/**************************************************//**
19
/******************************************************
21
20
The simple hash table utility
23
22
Created 5/20/1997 Heikki Tuuri
31
30
#include "mem0mem.h"
33
#ifndef UNIV_HOTBACKUP
34
/************************************************************//**
32
/****************************************************************
35
33
Reserves the mutex for a fold value in a hash table. */
40
hash_table_t* table, /*!< in: hash table */
41
ulint fold) /*!< in: fold */
38
hash_table_t* table, /* in: hash table */
39
ulint fold) /* in: fold */
43
41
mutex_enter(hash_get_mutex(table, fold));
46
/************************************************************//**
44
/****************************************************************
47
45
Releases the mutex for a fold value in a hash table. */
52
hash_table_t* table, /*!< in: hash table */
53
ulint fold) /*!< in: fold */
50
hash_table_t* table, /* in: hash table */
51
ulint fold) /* in: fold */
55
53
mutex_exit(hash_get_mutex(table, fold));
58
/************************************************************//**
56
/****************************************************************
59
57
Reserves all the mutexes of a hash table, in an ascending order. */
62
60
hash_mutex_enter_all(
63
61
/*=================*/
64
hash_table_t* table) /*!< in: hash table */
62
hash_table_t* table) /* in: hash table */
74
/************************************************************//**
72
/****************************************************************
75
73
Releases all the mutexes of a hash table. */
78
76
hash_mutex_exit_all(
79
77
/*================*/
80
hash_table_t* table) /*!< in: hash table */
78
hash_table_t* table) /* in: hash table */
86
84
mutex_exit(table->mutexes + i);
89
#endif /* !UNIV_HOTBACKUP */
91
/*************************************************************//**
88
/*****************************************************************
92
89
Creates a hash table with >= n array cells. The actual number of cells is
93
chosen to be a prime number slightly bigger than n.
94
@return own: created table */
90
chosen to be a prime number slightly bigger than n. */
99
ulint n) /*!< in: number of array cells */
95
/* out, own: created table */
96
ulint n) /* in: number of array cells */
101
98
hash_cell_t* array;
109
106
array = ut_malloc(sizeof(hash_cell_t) * prime);
108
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
109
table->adaptive = FALSE;
110
#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
111
111
table->array = array;
112
112
table->n_cells = prime;
113
#ifndef UNIV_HOTBACKUP
114
# if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
115
table->adaptive = FALSE;
116
# endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
117
113
table->n_mutexes = 0;
118
114
table->mutexes = NULL;
119
115
table->heaps = NULL;
120
#endif /* !UNIV_HOTBACKUP */
121
116
table->heap = NULL;
122
117
table->magic_n = HASH_TABLE_MAGIC_N;
130
/*************************************************************//**
125
/*****************************************************************
131
126
Frees a hash table. */
136
hash_table_t* table) /*!< in, own: hash table */
131
hash_table_t* table) /* in, own: hash table */
138
#ifndef UNIV_HOTBACKUP
139
133
ut_a(table->mutexes == NULL);
140
#endif /* !UNIV_HOTBACKUP */
142
135
ut_free(table->array);
146
#ifndef UNIV_HOTBACKUP
147
/*************************************************************//**
139
/*****************************************************************
148
140
Creates a mutex array to protect a hash table. */
151
143
hash_create_mutexes_func(
152
144
/*=====================*/
153
hash_table_t* table, /*!< in: hash table */
145
hash_table_t* table, /* in: hash table */
154
146
#ifdef UNIV_SYNC_DEBUG
155
ulint sync_level, /*!< in: latching order level of the
147
ulint sync_level, /* in: latching order level of the
156
148
mutexes: used in the debug version */
157
149
#endif /* UNIV_SYNC_DEBUG */
158
ulint n_mutexes) /*!< in: number of mutexes, must be a
150
ulint n_mutexes) /* in: number of mutexes, must be a