~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/ha/hash0hash.c

  • Committer: Brian Aker
  • Date: 2010-05-27 01:22:55 UTC
  • mto: This revision was merged to the branch mainline in revision 1568.
  • Revision ID: brian@gaz-20100527012255-ssmjt4un8ptpg4jv
Remove dead .opt files. Removed two options from Innodb which do not relate
to drizzle (backwards compatible options for old MySQL). 

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
/**************************************************//**
20
 
@file ha/hash0hash.c
21
 
The simple hash table utility
22
 
 
23
 
Created 5/20/1997 Heikki Tuuri
24
 
*******************************************************/
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
 
Reserves the mutex for a fold value in a hash table. */
36
 
UNIV_INTERN
37
 
void
38
 
hash_mutex_enter(
39
 
/*=============*/
40
 
        hash_table_t*   table,  /*!< in: hash table */
41
 
        ulint           fold)   /*!< in: fold */
42
 
{
43
 
        mutex_enter(hash_get_mutex(table, fold));
44
 
}
45
 
 
46
 
/************************************************************//**
47
 
Releases the mutex for a fold value in a hash table. */
48
 
UNIV_INTERN
49
 
void
50
 
hash_mutex_exit(
51
 
/*============*/
52
 
        hash_table_t*   table,  /*!< in: hash table */
53
 
        ulint           fold)   /*!< in: fold */
54
 
{
55
 
        mutex_exit(hash_get_mutex(table, fold));
56
 
}
57
 
 
58
 
/************************************************************//**
59
 
Reserves all the mutexes of a hash table, in an ascending order. */
60
 
UNIV_INTERN
61
 
void
62
 
hash_mutex_enter_all(
63
 
/*=================*/
64
 
        hash_table_t*   table)  /*!< in: hash table */
65
 
{
66
 
        ulint   i;
67
 
 
68
 
        for (i = 0; i < table->n_mutexes; i++) {
69
 
 
70
 
                mutex_enter(table->mutexes + i);
71
 
        }
72
 
}
73
 
 
74
 
/************************************************************//**
75
 
Releases all the mutexes of a hash table. */
76
 
UNIV_INTERN
77
 
void
78
 
hash_mutex_exit_all(
79
 
/*================*/
80
 
        hash_table_t*   table)  /*!< in: hash table */
81
 
{
82
 
        ulint   i;
83
 
 
84
 
        for (i = 0; i < table->n_mutexes; i++) {
85
 
 
86
 
                mutex_exit(table->mutexes + i);
87
 
        }
88
 
}
89
 
#endif /* !UNIV_HOTBACKUP */
90
 
 
91
 
/*************************************************************//**
92
 
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 */
95
 
UNIV_INTERN
96
 
hash_table_t*
97
 
hash_create(
98
 
/*========*/
99
 
        ulint   n)      /*!< in: number of array cells */
100
 
{
101
 
        hash_cell_t*    array;
102
 
        ulint           prime;
103
 
        hash_table_t*   table;
104
 
 
105
 
        prime = ut_find_prime(n);
106
 
 
107
 
        table = mem_alloc(sizeof(hash_table_t));
108
 
 
109
 
        array = ut_malloc(sizeof(hash_cell_t) * prime);
110
 
 
111
 
        table->array = array;
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
 
        table->n_mutexes = 0;
118
 
        table->mutexes = NULL;
119
 
        table->heaps = NULL;
120
 
#endif /* !UNIV_HOTBACKUP */
121
 
        table->heap = NULL;
122
 
        ut_d(table->magic_n = HASH_TABLE_MAGIC_N);
123
 
 
124
 
        /* Initialize the cell array */
125
 
        hash_table_clear(table);
126
 
 
127
 
        return(table);
128
 
}
129
 
 
130
 
/*************************************************************//**
131
 
Frees a hash table. */
132
 
UNIV_INTERN
133
 
void
134
 
hash_table_free(
135
 
/*============*/
136
 
        hash_table_t*   table)  /*!< in, own: hash table */
137
 
{
138
 
        ut_ad(table);
139
 
        ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
140
 
#ifndef UNIV_HOTBACKUP
141
 
        ut_a(table->mutexes == NULL);
142
 
#endif /* !UNIV_HOTBACKUP */
143
 
 
144
 
        ut_free(table->array);
145
 
        mem_free(table);
146
 
}
147
 
 
148
 
#ifndef UNIV_HOTBACKUP
149
 
/*************************************************************//**
150
 
Creates a mutex array to protect a hash table. */
151
 
UNIV_INTERN
152
 
void
153
 
hash_create_mutexes_func(
154
 
/*=====================*/
155
 
        hash_table_t*   table,          /*!< in: hash table */
156
 
#ifdef UNIV_SYNC_DEBUG
157
 
        ulint           sync_level,     /*!< in: latching order level of the
158
 
                                        mutexes: used in the debug version */
159
 
#endif /* UNIV_SYNC_DEBUG */
160
 
        ulint           n_mutexes)      /*!< in: number of mutexes, must be a
161
 
                                        power of 2 */
162
 
{
163
 
        ulint   i;
164
 
 
165
 
        ut_ad(table);
166
 
        ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
167
 
        ut_a(n_mutexes > 0);
168
 
        ut_a(ut_is_2pow(n_mutexes));
169
 
 
170
 
        table->mutexes = mem_alloc(n_mutexes * sizeof(mutex_t));
171
 
 
172
 
        for (i = 0; i < n_mutexes; i++) {
173
 
                mutex_create(table->mutexes + i, sync_level);
174
 
        }
175
 
 
176
 
        table->n_mutexes = n_mutexes;
177
 
}
178
 
#endif /* !UNIV_HOTBACKUP */