drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
hash0hash.cc
1/*****************************************************************************
2
3Copyright (C) 1997, 2009, Innobase Oy. All Rights Reserved.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License as published by the Free Software
7Foundation; version 2 of the License.
8
9This program is distributed in the hope that it will be useful, but WITHOUT
10ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
13You should have received a copy of the GNU General Public License along with
14this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15St, Fifth Floor, Boston, MA 02110-1301 USA
16
17*****************************************************************************/
18
19/**************************************************/
25
26#include "hash0hash.h"
27#ifdef UNIV_NONINL
28#include "hash0hash.ic"
29#endif
30
31#include "mem0mem.h"
32
33#ifndef UNIV_HOTBACKUP
34
35# ifdef UNIV_PFS_MUTEX
36UNIV_INTERN mysql_pfs_key_t hash_table_mutex_key;
37# endif /* UNIV_PFS_MUTEX */
38
39/************************************************************/
41UNIV_INTERN
42void
43hash_mutex_enter(
44/*=============*/
45 hash_table_t* table,
46 ulint fold)
47{
48 mutex_enter(hash_get_mutex(table, fold));
49}
50
51/************************************************************/
53UNIV_INTERN
54void
55hash_mutex_exit(
56/*============*/
57 hash_table_t* table,
58 ulint fold)
59{
60 mutex_exit(hash_get_mutex(table, fold));
61}
62
63/************************************************************/
65UNIV_INTERN
66void
67hash_mutex_enter_all(
68/*=================*/
69 hash_table_t* table)
70{
71 ulint i;
72
73 for (i = 0; i < table->n_mutexes; i++) {
74
75 mutex_enter(table->mutexes + i);
76 }
77}
78
79/************************************************************/
81UNIV_INTERN
82void
83hash_mutex_exit_all(
84/*================*/
85 hash_table_t* table)
86{
87 ulint i;
88
89 for (i = 0; i < table->n_mutexes; i++) {
90
91 mutex_exit(table->mutexes + i);
92 }
93}
94#endif /* !UNIV_HOTBACKUP */
95
96/*************************************************************/
100UNIV_INTERN
101hash_table_t*
102hash_create(
103/*========*/
104 ulint n)
105{
106 hash_cell_t* array;
107 ulint prime;
108 hash_table_t* table;
109
110 prime = ut_find_prime(n);
111
112 table = static_cast<hash_table_t*>(mem_alloc(sizeof(hash_table_t)));
113
114 array = static_cast<hash_cell_t*>(ut_malloc(sizeof(hash_cell_t) * prime));
115
116 table->array = array;
117 table->n_cells = prime;
118#ifndef UNIV_HOTBACKUP
119# if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
120 table->adaptive = FALSE;
121# endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
122 table->n_mutexes = 0;
123 table->mutexes = NULL;
124 table->heaps = NULL;
125#endif /* !UNIV_HOTBACKUP */
126 table->heap = NULL;
127 ut_d(table->magic_n = HASH_TABLE_MAGIC_N);
128
129 /* Initialize the cell array */
130 hash_table_clear(table);
131
132 return(table);
133}
134
135/*************************************************************/
137UNIV_INTERN
138void
139hash_table_free(
140/*============*/
141 hash_table_t* table)
142{
143 ut_ad(table);
144 ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
145#ifndef UNIV_HOTBACKUP
146 ut_a(table->mutexes == NULL);
147#endif /* !UNIV_HOTBACKUP */
148
149 ut_free(table->array);
150 mem_free(table);
151}
152
153#ifndef UNIV_HOTBACKUP
154/*************************************************************/
156UNIV_INTERN
157void
158hash_create_mutexes_func(
159/*=====================*/
160 hash_table_t* table,
161#ifdef UNIV_SYNC_DEBUG
162 ulint sync_level,
164#endif /* UNIV_SYNC_DEBUG */
165 ulint n_mutexes)
167{
168 ulint i;
169
170 ut_ad(table);
171 ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
172 ut_a(n_mutexes > 0);
173 ut_a(ut_is_2pow(n_mutexes));
174
175 table->mutexes = static_cast<mutex_struct *>(mem_alloc(n_mutexes * sizeof(mutex_t)));
176
177 for (i = 0; i < n_mutexes; i++) {
178 mutex_create(hash_table_mutex_key,
179 table->mutexes + i, sync_level);
180 }
181
182 table->n_mutexes = n_mutexes;
183}
184#endif /* !UNIV_HOTBACKUP */
UNIV_INLINE mutex_t * hash_get_mutex(hash_table_t *table, ulint fold)
UNIV_INLINE void hash_table_clear(hash_table_t *table)
#define mem_free(PTR)
Definition mem0mem.h:243
#define mutex_t
Definition sync0types.h:31
#define ut_ad(EXPR)
Definition ut0dbg.h:127
#define ut_d(EXPR)
Definition ut0dbg.h:129
#define ut_a(EXPR)
Definition ut0dbg.h:105
UNIV_INTERN void ut_free(void *ptr)
Definition ut0mem.cc:294
UNIV_INTERN void * ut_malloc(ulint n)
Definition ut0mem.cc:235
UNIV_INTERN ulint ut_find_prime(ulint n) __attribute__((const))
#define ut_is_2pow(n)
Definition ut0ut.h:162