Drizzled Public API Documentation

hash0hash.cc
1 /*****************************************************************************
2 
3 Copyright (C) 1997, 2009, Innobase Oy. All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free Software
7 Foundation; version 2 of the License.
8 
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 
13 You should have received a copy of the GNU General Public License along with
14 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15 St, Fifth Floor, Boston, MA 02110-1301 USA
16 
17 *****************************************************************************/
18 
19 /**************************************************/
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
36 UNIV_INTERN mysql_pfs_key_t hash_table_mutex_key;
37 # endif /* UNIV_PFS_MUTEX */
38 
39 /************************************************************/
41 UNIV_INTERN
42 void
43 hash_mutex_enter(
44 /*=============*/
45  hash_table_t* table,
46  ulint fold)
47 {
48  mutex_enter(hash_get_mutex(table, fold));
49 }
50 
51 /************************************************************/
53 UNIV_INTERN
54 void
55 hash_mutex_exit(
56 /*============*/
57  hash_table_t* table,
58  ulint fold)
59 {
60  mutex_exit(hash_get_mutex(table, fold));
61 }
62 
63 /************************************************************/
65 UNIV_INTERN
66 void
67 hash_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 /************************************************************/
81 UNIV_INTERN
82 void
83 hash_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 /*************************************************************/
100 UNIV_INTERN
102 hash_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 /*************************************************************/
137 UNIV_INTERN
138 void
139 hash_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 /*************************************************************/
156 UNIV_INTERN
157 void
158 hash_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 */