summaryrefslogtreecommitdiff
path: root/storage/innobase/include/btr0sea.ic
diff options
context:
space:
mode:
Diffstat (limited to 'storage/innobase/include/btr0sea.ic')
-rw-r--r--storage/innobase/include/btr0sea.ic155
1 files changed, 147 insertions, 8 deletions
diff --git a/storage/innobase/include/btr0sea.ic b/storage/innobase/include/btr0sea.ic
index 0bd869be136..4fd76810ea0 100644
--- a/storage/innobase/include/btr0sea.ic
+++ b/storage/innobase/include/btr0sea.ic
@@ -1,6 +1,6 @@
/*****************************************************************************
-Copyright (c) 1996, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1996, 2015, Oracle and/or its affiliates. All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
@@ -29,7 +29,6 @@ Created 2/17/1996 Heikki Tuuri
/*********************************************************************//**
Updates the search info. */
-UNIV_INTERN
void
btr_search_info_update_slow(
/*========================*/
@@ -38,7 +37,7 @@ btr_search_info_update_slow(
/********************************************************************//**
Returns search info for an index.
-@return search info; search mutex reserved */
+@return search info; search mutex reserved */
UNIV_INLINE
btr_search_t*
btr_search_get_info(
@@ -57,13 +56,14 @@ btr_search_info_update(
dict_index_t* index, /*!< in: index of the cursor */
btr_cur_t* cursor) /*!< in: cursor which was just positioned */
{
- btr_search_t* info;
+ ut_ad(!rw_lock_own(btr_get_search_latch(index), RW_LOCK_S));
+ ut_ad(!rw_lock_own(btr_get_search_latch(index), RW_LOCK_X));
-#ifdef UNIV_SYNC_DEBUG
- ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_SHARED));
- ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_EX));
-#endif /* UNIV_SYNC_DEBUG */
+ if (dict_index_is_spatial(index) || !btr_search_enabled) {
+ return;
+ }
+ btr_search_t* info;
info = btr_search_get_info(index);
info->hash_analysis++;
@@ -80,3 +80,142 @@ btr_search_info_update(
btr_search_info_update_slow(info, cursor);
}
+
+/** X-Lock the search latch (corresponding to given index)
+@param[in] index index handler */
+UNIV_INLINE
+void
+btr_search_x_lock(const dict_index_t* index)
+{
+ rw_lock_x_lock(btr_get_search_latch(index));
+}
+
+/** X-Unlock the search latch (corresponding to given index)
+@param[in] index index handler */
+UNIV_INLINE
+void
+btr_search_x_unlock(const dict_index_t* index)
+{
+ rw_lock_x_unlock(btr_get_search_latch(index));
+}
+
+/** Lock all search latches in exclusive mode. */
+UNIV_INLINE
+void
+btr_search_x_lock_all()
+{
+ for (ulint i = 0; i < btr_ahi_parts; ++i) {
+ rw_lock_x_lock(btr_search_latches[i]);
+ }
+}
+
+/** Unlock all search latches from exclusive mode. */
+UNIV_INLINE
+void
+btr_search_x_unlock_all()
+{
+ for (ulint i = 0; i < btr_ahi_parts; ++i) {
+ rw_lock_x_unlock(btr_search_latches[i]);
+ }
+}
+
+/** S-Lock the search latch (corresponding to given index)
+@param[in] index index handler */
+UNIV_INLINE
+void
+btr_search_s_lock(const dict_index_t* index)
+{
+ rw_lock_s_lock(btr_get_search_latch(index));
+}
+
+/** S-Unlock the search latch (corresponding to given index)
+@param[in] index index handler */
+UNIV_INLINE
+void
+btr_search_s_unlock(const dict_index_t* index)
+{
+ rw_lock_s_unlock(btr_get_search_latch(index));
+}
+
+/** Lock all search latches in shared mode. */
+UNIV_INLINE
+void
+btr_search_s_lock_all()
+{
+ for (ulint i = 0; i < btr_ahi_parts; ++i) {
+ rw_lock_s_lock(btr_search_latches[i]);
+ }
+}
+
+/** Unlock all search latches from shared mode. */
+UNIV_INLINE
+void
+btr_search_s_unlock_all()
+{
+ for (ulint i = 0; i < btr_ahi_parts; ++i) {
+ rw_lock_s_unlock(btr_search_latches[i]);
+ }
+}
+
+#ifdef UNIV_DEBUG
+/** Check if thread owns all the search latches.
+@param[in] mode lock mode check
+@retval true if owns all of them
+@retval false if does not own some of them */
+UNIV_INLINE
+bool
+btr_search_own_all(ulint mode)
+{
+ for (ulint i = 0; i < btr_ahi_parts; ++i) {
+ if (!rw_lock_own(btr_search_latches[i], mode)) {
+ return(false);
+ }
+ }
+ return(true);
+}
+
+/** Check if thread owns any of the search latches.
+@param[in] mode lock mode check
+@retval true if owns any of them
+@retval false if owns no search latch */
+UNIV_INLINE
+bool
+btr_search_own_any(ulint mode)
+{
+ for (ulint i = 0; i < btr_ahi_parts; ++i) {
+ if (rw_lock_own(btr_search_latches[i], mode)) {
+ return(true);
+ }
+ }
+ return(false);
+}
+#endif /* UNIV_DEBUG */
+
+/** Get the adaptive hash search index latch for a b-tree.
+@param[in] index b-tree index
+@return latch */
+UNIV_INLINE
+rw_lock_t*
+btr_get_search_latch(const dict_index_t* index)
+{
+ ut_ad(index != NULL);
+
+ ulint ifold = ut_fold_ulint_pair(index->id, index->space);
+
+ return(btr_search_latches[ifold % btr_ahi_parts]);
+}
+
+/** Get the hash-table based on index attributes.
+A table is selected from an array of tables using pair of index-id, space-id.
+@param[in] index index handler
+@return hash table */
+UNIV_INLINE
+hash_table_t*
+btr_get_search_table(const dict_index_t* index)
+{
+ ut_ad(index != NULL);
+
+ ulint ifold = ut_fold_ulint_pair(index->id, index->space);
+
+ return(btr_search_sys->hash_tables[ifold % btr_ahi_parts]);
+}