00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00026 #include "hash0hash.h"
00027 #ifdef UNIV_NONINL
00028 #include "hash0hash.ic"
00029 #endif
00030
00031 #include "mem0mem.h"
00032
00033 #ifndef UNIV_HOTBACKUP
00034
00035 # ifdef UNIV_PFS_MUTEX
00036 UNIV_INTERN mysql_pfs_key_t hash_table_mutex_key;
00037 # endif
00038
00039
00041 UNIV_INTERN
00042 void
00043 hash_mutex_enter(
00044
00045 hash_table_t* table,
00046 ulint fold)
00047 {
00048 mutex_enter(hash_get_mutex(table, fold));
00049 }
00050
00051
00053 UNIV_INTERN
00054 void
00055 hash_mutex_exit(
00056
00057 hash_table_t* table,
00058 ulint fold)
00059 {
00060 mutex_exit(hash_get_mutex(table, fold));
00061 }
00062
00063
00065 UNIV_INTERN
00066 void
00067 hash_mutex_enter_all(
00068
00069 hash_table_t* table)
00070 {
00071 ulint i;
00072
00073 for (i = 0; i < table->n_mutexes; i++) {
00074
00075 mutex_enter(table->mutexes + i);
00076 }
00077 }
00078
00079
00081 UNIV_INTERN
00082 void
00083 hash_mutex_exit_all(
00084
00085 hash_table_t* table)
00086 {
00087 ulint i;
00088
00089 for (i = 0; i < table->n_mutexes; i++) {
00090
00091 mutex_exit(table->mutexes + i);
00092 }
00093 }
00094 #endif
00095
00096
00100 UNIV_INTERN
00101 hash_table_t*
00102 hash_create(
00103
00104 ulint n)
00105 {
00106 hash_cell_t* array;
00107 ulint prime;
00108 hash_table_t* table;
00109
00110 prime = ut_find_prime(n);
00111
00112 table = static_cast<hash_table_t*>(mem_alloc(sizeof(hash_table_t)));
00113
00114 array = static_cast<hash_cell_t*>(ut_malloc(sizeof(hash_cell_t) * prime));
00115
00116 table->array = array;
00117 table->n_cells = prime;
00118 #ifndef UNIV_HOTBACKUP
00119 # if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
00120 table->adaptive = FALSE;
00121 # endif
00122 table->n_mutexes = 0;
00123 table->mutexes = NULL;
00124 table->heaps = NULL;
00125 #endif
00126 table->heap = NULL;
00127 ut_d(table->magic_n = HASH_TABLE_MAGIC_N);
00128
00129
00130 hash_table_clear(table);
00131
00132 return(table);
00133 }
00134
00135
00137 UNIV_INTERN
00138 void
00139 hash_table_free(
00140
00141 hash_table_t* table)
00142 {
00143 ut_ad(table);
00144 ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
00145 #ifndef UNIV_HOTBACKUP
00146 ut_a(table->mutexes == NULL);
00147 #endif
00148
00149 ut_free(table->array);
00150 mem_free(table);
00151 }
00152
00153 #ifndef UNIV_HOTBACKUP
00154
00156 UNIV_INTERN
00157 void
00158 hash_create_mutexes_func(
00159
00160 hash_table_t* table,
00161 #ifdef UNIV_SYNC_DEBUG
00162 ulint sync_level,
00164 #endif
00165 ulint n_mutexes)
00167 {
00168 ulint i;
00169
00170 ut_ad(table);
00171 ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
00172 ut_a(n_mutexes > 0);
00173 ut_a(ut_is_2pow(n_mutexes));
00174
00175 table->mutexes = static_cast<mutex_struct *>(mem_alloc(n_mutexes * sizeof(mutex_t)));
00176
00177 for (i = 0; i < n_mutexes; i++) {
00178 mutex_create(hash_table_mutex_key,
00179 table->mutexes + i, sync_level);
00180 }
00181
00182 table->n_mutexes = n_mutexes;
00183 }
00184 #endif